Right now h11 raises a LocalProtocolError if you try to send a non-empty Data event in response to a HEAD request. This can be a nuisance in a catch-all handler, such as the maybe_send_error_response in your Curio example. Notice how there’s no way for maybe_send_error_response to tell that it’s not supposed to send data, because it has no access to the request event, and wrapper.conn.our_state is still SEND_BODY. Handling this cleanly would require some refactoring of the example code. Not to mention that you have to remember HEAD exists in the first place.
Would it perhaps be better if the state machine went from SEND_RESPONSE directly to DONE in this case, so the handler could readily pick that up?
Alternatively, what if h11 just silently ignored the Data events when responding to a HEAD request? (I can see the potential problems with this though: an application could keep “streaming” a long response into the bit bucket; also it’s not clear what to do with trailers if those pop up eventually.)
These are just random ideas not grounded in any serious use of h11; feel free to ignore if this doesn’t sound good.
Right now h11 raises a
LocalProtocolErrorif you try to send a non-emptyDataevent in response to a HEAD request. This can be a nuisance in a catch-all handler, such as themaybe_send_error_responsein your Curio example. Notice how there’s no way formaybe_send_error_responseto tell that it’s not supposed to send data, because it has no access to the request event, andwrapper.conn.our_stateis stillSEND_BODY. Handling this cleanly would require some refactoring of the example code. Not to mention that you have to remember HEAD exists in the first place.Would it perhaps be better if the state machine went from
SEND_RESPONSEdirectly toDONEin this case, so the handler could readily pick that up?Alternatively, what if h11 just silently ignored the
Dataevents when responding to a HEAD request? (I can see the potential problems with this though: an application could keep “streaming” a long response into the bit bucket; also it’s not clear what to do with trailers if those pop up eventually.)These are just random ideas not grounded in any serious use of h11; feel free to ignore if this doesn’t sound good.