Skip to content
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

Merged
merged 6 commits into from
Jul 9, 2018
Merged

http: chunked transfer encoding #174

merged 6 commits into from
Jul 9, 2018

Conversation

legendecas
Copy link
Contributor

@legendecas legendecas commented Jul 3, 2018

Expect resolving #133

http client:

  • default encoding of http request shall be chunked
  • wrap http chunk with chunk header and a \r\n trailing

http server:

  • default encoding of response shall be chunked
  • wrap http chunk with chunk header and a \r\n trailing

  • all tests pass
  • test case over chunked encoding
  • document

@legendecas legendecas changed the title http: chunked transfer encoding [WIP] http: chunked transfer encoding Jul 3, 2018
@yorkie yorkie added the http label Jul 3, 2018
this.path = options.path || '/';

var methodIsString = (typeof method === 'string');
if (methodIsString && method) {
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

@yorkie yorkie Jul 5, 2018

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

@@ -206,6 +220,13 @@ function responseOnEnd() {
}
}

ClientRequest.prototype._implicitHeader = function _implicitHeader() {
if (this._header) {
throw new Error('Cannot render headers after they are sent');
Copy link
Member

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?

@@ -17,14 +17,18 @@
var util = require('util');
var stream = require('stream');

var crlf_buf = Buffer.from('\r\n');
Copy link
Member

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);
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

@yorkie yorkie Jul 5, 2018

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Member

@yorkie yorkie Jul 5, 2018

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?

Copy link
Contributor Author

@legendecas legendecas Jul 5, 2018

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why removing the _bodyLength?

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good explain! 👍

Copy link
Member

@yorkie yorkie left a 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.

@legendecas legendecas changed the title [WIP] http: chunked transfer encoding http: chunked transfer encoding Jul 5, 2018

return ret;
this._send(len.toString(16), 'latin1', null);
Copy link
Member

@yorkie yorkie Jul 5, 2018

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.

@yorkie
Copy link
Member

yorkie commented Jul 9, 2018

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.

@legendecas
Copy link
Contributor Author

legendecas commented Jul 9, 2018

Document is updated! 🤠

@yorkie yorkie merged commit 1226ad5 into master Jul 9, 2018
@yorkie yorkie deleted the http-chunked-encoding branch July 9, 2018 12:04
@yorkie
Copy link
Member

yorkie commented Jul 9, 2018

Merged @legendecas :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants