-
Notifications
You must be signed in to change notification settings - Fork 1
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
Response Status Line parsing is error prone #5
Comments
Mhhh, I don't know if it really would make sense to do it that way. If you receive some invalid messages on a connection that should be a HTTP connection I would define this as a broken connection. In addition using a byte[] as an inout parameter is wrong in my point of view. The input should always be a NIO channel. Only by doing it that way a real streaming of HTTP messages can be created. Example: 1: Create Channel (Connect to endpoint) Based on this the API will look more like:
Another option would be the use of a stream. In that case the API would look like this:
By using the the stream API we do not have a change to handle an error without adding a error handler as a param to the method:
So several possibilities :) What do you think? |
I fully agree with the concept, its actually a good example. Providing a stream of HttpResponses is also a good idea, you probably have some use case in mind here. Having the option to work with Nevertheless the parsing as it happens right now (no matter which branch) is not really nice, the more I read from HTTP the more different I would like to do it. Which means that a HttpResponse could be separated into several internal, functional classes: HttpResponse could incorporate:
boolean validity = new ResponseLine(...).isValid() Unexpected errors could be wrapped into a ResponseParsingException (unchecked) or so.
I was playing with different requests and tested multiple response types and the current HttpResponse.read*(...) failed with ugly errors multiple times. Those internal classes would also have the advantage to provide meaning full error types. Or is that too overblown? As there is no "public" API yet, we're still free to shape it. |
Instead of a |
|
With current implementation in HttpResponseReader in case of invalid messages there would be something like an IllegalArgumentError etc. Here it would be better to possibly return an Optional with a HttpResponse embedded when the response is valid. If response line is invalid, returning an empty Optional would be okay.
Consumers the can be called by:
Response status line is defined in http://httpwg.org/specs/rfc7230.html#status.line.
A valid response status line:
Placing this into separate class / method would make it testable. Here similar approach would be possible for Request Line.
The text was updated successfully, but these errors were encountered: