Skip to content

No WAI Response composers work to send HTTP 103 Early Hints #970

@thomasjm

Description

@thomasjm

I recently landed snoyberg/http-client#524 (CC @snoyberg) provide HTTP 103 Early Hints support in http-client. Now I'm trying to extend this support to http-reverse-proxy, and running into the following problem.

The idea of HTTP 103 Early Hints is that an HTTP server can send an initial HTTP status code of 103, along with some headers. This means "the full response is still processing, but in the meantime here are some things you as a client can do to start preparing for it." Primarily this is for browsers to start pre-fetching assets that will be needed. The server can send multiple 103 Early Hints sections before it concludes with the full response.

The key issue here is, we want to start sending status lines and headers to the client, but we don't know what the final status will be yet! It might be 200, or some error might happen during processing and it might be something else.

All of the higher-level Response composers in WAI expect a Status up front: responseFile, responseBuilder, responseLbs, and even responseStream. (This last one works only for streaming the body, not the status lines/headers.)

This leaves only responseRaw. I've tried to use this to implement the reverse proxy here, but it doesn't quite work. My attempt actually sends the 103 Early Hints section, but then closes the connection prematurely. I think this is because responseRaw is mainly intended for WebSocket upgrades, and has this line in its documentation:

In the event that you read from the request body before returning a responseRaw, behavior is undefined.

This undefined behavior is inconsistent with using responseRaw as part of a reverse proxy.

I think to fix this, WAI needs a new response composer, maybe a different flavor of responseRaw. Note that the current responseRaw also provides a function to read bytes from the client, which we don't need for this application. Presumably a version without this wouldn't have the undefined behavior issue.

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