Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove HTTP::RequestProcessor #7248

Open
straight-shoota opened this issue Jan 2, 2019 · 5 comments
Open

Remove HTTP::RequestProcessor #7248

straight-shoota opened this issue Jan 2, 2019 · 5 comments

Comments

@straight-shoota
Copy link
Member

The HTTP::RequestProcessor class simply delegates the request handling for HTTP::Server. I don't think this needs to be a distinct type. There is a 1:1 coupling between each server and processor, and it basically consists of one method and two ivars which can easily be integrated into HTTP::Server directly.

I suppose the class was originally introduced in ecdcea9 as an easy to use interface for testing request processing, since HTTP::Server required to set up a TCP server for that and RequestProcessor operates on IOs which can be easily be tested using IO::Memory.

After #5776 this is no longer the case. Setting up a HTTP::Server instance doesn't anymore instantly open a TCP server. It could easily be used for testing handler chains without going through any network socket.

HTTP::RequestProcessor is part of the public API, but has no documentation. I doubt it has any practical use case where it couldn't be substituted by HTTP::Server directly.

@RX14
Copy link
Contributor

RX14 commented Jan 3, 2019

I don't mind the split, purely on a code separation point of view. HTTP::Server dealing with the incmping connections and HTTP::RequestProcessor dealing with an individual connection's lifecycle makes sense to me.

I don't think it needs to be a documented type though.

@straight-shoota
Copy link
Member Author

@RX14 I agree on the separation point. But it's really just a single method with almost no state. That single ivar could even be refactored out by passing in a server instance and asking if it's closed.

I do like however that the #process is part of the public API, this makes it easy to re-use the processing logic with a different network interface implementation (for example in Earl::HTTPServer). When #process is transferred to HTTP::Server, this method should stay public.

@RX14
Copy link
Contributor

RX14 commented Jan 3, 2019

@straight-shoota yes, it's a single method, but it's a long one and I wouldn't want to make http/server.cr longer. Any complaints of mine are purely stylistic.

@straight-shoota
Copy link
Member Author

Oh, yes. I'd actually too prefer to leave the code in request_processor.cr and just reopen HTTP::Server instead of creating a new class.

@RX14
Copy link
Contributor

RX14 commented Jan 4, 2019

I dislike splitting a single class between multiple files even more. It always makes it confusing where things come from. If it's obviously a different type you're calling a method on (RequestProcessor), you know the method definition will be in a different file, and you know where to look for it.

I'd be very happy if RequestProcessor became an empty struct with no state, and a simpler API. But I'd prefer to keep it it's own type. It should be :nodoc: or a private type though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants