CrowdHailer / Ace

HTTP web server and client, supports http1 and http2
https://hex.pm/packages/ace
MIT License
304 stars 26 forks source link

handle_tail doesn't get called with GET requests #117

Closed nietaki closed 5 years ago

nietaki commented 6 years ago

(or probably all requests with no body)

I was writing a couple of handlers using handle_head, handle_data and handle_tail (as opposed to handle_request) where I was only sending the response in handle_tail, after doing some processing beforehand. This worked well for POST requests with body, but for GET requests handle_data and handle_tail wasn't called and the response was never completed. It was still confusing to me after looking at the docs.

After some consults I now understand that if the request in handle_head has body set to false I shouldn't be expecting the other callbacks to be called and I should do all the work in handle_head and potentially handle_info.

While I see that this is a perfectly workable approach, I think handle_tail should be called in all cases.

So what I'm proposing is always calling handle_tail callback for all requests (if handled with the 3 callbacks approach, naturally) and only calling handle_data if there is body in the request. Also calling handle_data with an empty binary chunk as well probably makes less sense.

Anyone opposed?

CrowdHailer commented 5 years ago

I think the reason I don't call handle_tail was because that maps more closely to the messages as described here https://tools.ietf.org/html/rfc7540#section-8.1

The tail being the optional headers frame after the body.

Adding this for context rather than a reason not to proceed

nietaki commented 5 years ago

This is now explained in the README: https://github.com/nietaki/raxx#requestresponse-flow