Skip to content

Consider a more convenient API for responses to HEAD #42

@vfaronov

Description

@vfaronov

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions