-
Notifications
You must be signed in to change notification settings - Fork 46
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
http: chunked transfer encoding #174
Conversation
f140c00
to
fb78ff6
Compare
this.path = options.path || '/'; | ||
|
||
var methodIsString = (typeof method === 'string'); | ||
if (methodIsString && method) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we just defines all methods and check by methods[method]
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it is possible to use a custom method rather than most common methods like GET, POST in http request.
#ref: https://tools.ietf.org/html/rfc2616#section-5.1.1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't need to support the whole context-free grammar for Method
, a reduced CFG is:
Method = "OPTIONS" | "GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "TRACE" | "CONNECT"
An origin server SHOULD return the status code 405 (Method Not Allowed) if the method is known by the origin server but not allowed for the requested resource, and 501 (Not Implemented) if the method is unrecognized or not implemented by the origin server.
As the above description, we could respond a 501 for those methods is invalid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion, if a custom method shall be considered as supported or not is up to servers rather than an client library since it's valid by definition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, really think there are not too much developers to use the custom feature. But let's support it, that's reasonable than me.
src/js/http_client.js
Outdated
@@ -206,6 +220,13 @@ function responseOnEnd() { | |||
} | |||
} | |||
|
|||
ClientRequest.prototype._implicitHeader = function _implicitHeader() { | |||
if (this._header) { | |||
throw new Error('Cannot render headers after they are sent'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code seems say: if header does not exist, it's unable to render again, because it can be sent? Why the this._header
means the response has been sent?
src/js/http_outgoing.js
Outdated
@@ -17,14 +17,18 @@ | |||
var util = require('util'); | |||
var stream = require('stream'); | |||
|
|||
var crlf_buf = Buffer.from('\r\n'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use crlf
or crlfBuf
?
|
||
return ret; | ||
this._send(len.toString(16), 'latin1', null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might have no "latin1" encoding yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An alias of latin1
is binary
, which is one-byte encoded.
I've tested over this, data have been correctly encoded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, see the following function: https://github.com/Rokid/ShadowNode/blob/3d408ea40191c693e470a9d0a48be60a98b84f38/src/js/net.js#L160-L165
It shows the encoding latin1
did not be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like it doesn't support specify encoding anyway. but for better compatibility in the future implementations, it's reasonable to leave as it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The write(chunk, callback)
only has 2 arguments, however we pass it with 3 arguments. Therefore this makes confusion and inconsistent, let's do that after we changed the function is 100% same as Node.js.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we support encoding in .write(chunk, encoding, callback)
method before this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😅Actually the chunk header is a hex number so that's ok to use default ascii encoding.
It's ok to remove the encoding argument at this scenario.
|
||
function OutgoingMessage() { | ||
stream.Stream.call(this); | ||
|
||
this.writable = true; | ||
|
||
this._hasBody = true; | ||
this._bodyLength = 0; | ||
this._contentLength = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why removing the _bodyLength
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's renamed for align with naming of the header Content-Length
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good explain! 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just leave some comments.
|
||
return ret; | ||
this._send(len.toString(16), 'latin1', null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, see the following function: https://github.com/Rokid/ShadowNode/blob/3d408ea40191c693e470a9d0a48be60a98b84f38/src/js/net.js#L160-L165
It shows the encoding latin1
did not be used.
How is this in progress @legendecas? Currently I think this should be lack of only the documents, because of #184 did fix the encoding params. |
3d408ea
to
75b06e2
Compare
Document is updated! 🤠 |
Merged @legendecas :) |
Expect resolving #133
http client:
http
request shall be chunked\r\n
trailinghttp server:
\r\n
trailing