-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
Expose and write headers on 1xx intermediate status codes #27921
Comments
This comment has been minimized.
This comment has been minimized.
This is a good example for me, although
I'm willing to work for it.
= 。 = I probably prefer what's discussed in "Make http.OutgoingMessage._writeRaw public" #22624 to this. @node/http(This @ doesn't work very well) What do you think? |
This comment has been minimized.
This comment has been minimized.
@zero1five #22624 is not a good solution for this issue. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Maybe it is better just to add custom message to writeProcessing public function? ServerResponse.prototype.writeProcessing = function writeProcessing(cb) {
this._writeRaw(`HTTP/1.1 102 Processing${CRLF}${CRLF}`, 'ascii', cb);
}; |
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document. |
This is still desired. |
There does not seem to be collaborators interested in picking it up. Given this has been opened for 3 years without much activity, I'd close it. Feel free to let us know if you would like to implement this yourself. |
I second that this method would a handy addition to Node;s API. Is there still interest in accepting a PR for this? |
@Acconut Since this feature request is partially accepted (I wrote #28459) it may be best to file a new issue that deals exclusively with enabling multiple calls to response.writeHead. As for a PR, last time I took a look at it, Node.js had many optimizations in the header sending logic that are difficult to untangle. |
Background: I'm currently working on a document for standardizing how servers may communicate intermediate status of a long-running operation over HTTP (operations running minutes to days). Part of this involves use of 1xx status codes, available in HTTP/1.1 and HTTP/2.
HTTP specifies that a request may have multiple 1xx responses before a final 2xx-5xx response. These responses, like any other, may have headers:
101 Switching Protocols
,102 Processing
, and103 Early Hints
are all known to use headers to convey additional information about the intermediate status. (For example, 101 uses Upgrade, 102 uses Status-URI, and 103 uses Link).There is currently seemingly no way to write or read these headers. Given the definition of 1xx (which is mandatory in HTTP/1.1 and HTTP/2), I would expect to be able to call
ServerResponse#writeHead
multiple times with a 1xx status code, however, this does not flush the headers to the response, and appears to cause an error to be thrown once the final headers are written! Node.js addedServerResponse#writeProcessing
in v10.0.0, however, this is specific to a single status code, does not support headers, and is not forward compatible with future status codes.I would also expect the
ClientRequest#on("information")
event to include a headers object, so I can read this data.The only known workarounds are to use
ServerResponse#_writeRaw
which is not a public API; and the only available option for clients is to parse responses manually.Here is a script demonstrating the expected behavior:
When
_writeRaw
is used, the Node.js client sees only thestatusCode
:When
_writeRaw
is used,curl
is able to parse the response as expected:However, when
writeHead
is used, the data never makes it out of the socket, and an error is emitted towards the end:In summary:
ClientRequest#on("information")
should expose a res-like object with headers, andServerResponse#writeHead
should allow multiple calls with a 1xx status code that is immediately flushed to the socket.The text was updated successfully, but these errors were encountered: