Skip to main content
17 events
when toggle format what by license comment
Aug 17 at 19:12 comment added Mast @guest271314 Please keep this conversation civilized. The alternative is throwing out all comments on this answer, which serves no one. The will of reviewers and the scope of a review is something you can try to discuss on meta (it may have been discussed before), not below answers. Answers are written by volunteers. If they contain information you don't want to use, don't use it. That doesn't make the information wrong.
Aug 17 at 18:20 comment added guest271314 @J_H Well, perhaps your scope is too narrow. I did a +1 on the answer solely because of the suggestion to name the 13 and 10 variables; that's it github.com/guest271314/direct-sockets-http-ws-server/blob/main/…. Your ability to maintain the code in a PR is proportional to your will to do so. Conjecture on all SE Web sites is plentiful... not just Code Review.
Aug 17 at 16:32 history edited Maarten Bodewes CC BY-SA 4.0
added 18 characters in body
Aug 17 at 16:23 comment added J_H "maybe you shouldn't have answered the question?" Maarten was volunteering some valuable feedback about whether the OP code is maintainable, as at least one reviewer found it a bit opaque. When we do a Pull Request on a feature branch, prior to merging it to main, we're trying to answer two questions about the code. (1.) Is it correct? (2.) Is it maintainable? That 2nd item gets at whether team members, beyond the author, could fix bugs and add features. It addresses whether a project can recruit new contributors as circumstances change. The feedback on (2.) was "nope, not yet." I agree.
Aug 16 at 22:39 comment added Maarten Bodewes You don't need to assign it zero, you can just define the variable when you need it. If you cannot even accept that magic values / literals is a bad idea, then I've got nothing more to add. Constants don't take space. I'm out.
Aug 16 at 22:35 comment added guest271314 Since I posted the question I've gotten rid of the let chunkLength = "";. Now it's let chunkLength = 0; github.com/guest271314/direct-sockets-http-ws-server/blob/main/… because using strings is expensive gist.github.com/guest271314/…. I'm not using strings now. I think people who write HTTP servers pretty much know that 13 is \r and 10 is \n. We don't need string representations of those integers.
Aug 16 at 22:28 comment added Maarten Bodewes You mean outside of let chunkLength = ""; ? :P Joking aside, read top of answer first. The result is still 13 and 10, but it makes it clear that it is CRLF.
Aug 16 at 22:27 comment added guest271314 No idea what you mean then. There's no strings involved.
Aug 16 at 22:24 comment added Maarten Bodewes Not what I meant, in answer (on top). Chunking data is used in many protocols, I'd simply reference or even quote the specification.
Aug 16 at 22:17 comment added guest271314 "but I'd make clear why you are searching for the HTTP (or whatever) line end." I do. That's what the question is all about: parsing Transfer-Encoding: chunked. "And I'd use hex codes to match and not decimals" Using hex codes (strings) when you are getting Uint8Arrays in the server is far more expensive gist.github.com/guest271314/d6e932154e11fffb75fd7d1a4b25f4f5. You have to convert to a string by some means, e.g., Uint8Array.toHex() to get strings.
Aug 16 at 21:55 history edited Maarten Bodewes CC BY-SA 4.0
added 228 characters in body
Aug 16 at 21:53 comment added Maarten Bodewes The use of findIndex is of course OK, but I'd make clear why you are searching for the HTTP (or whatever) line end. And I'd use hex codes to match and not decimals, but that's already in the answer. Most (old school) devs will immediately recognize 0x0D and 0x0A but 13 and 10... not so much. I'll give hint how to do that in the answer.
Aug 16 at 17:53 comment added guest271314 Your thoughts about the use of findIndex() to locate \r\n if present in the Uint8Array?
Aug 15 at 3:49 comment added guest271314 I explained what is going on in OP. In prose and in code. I'm making a POST request using fetch() with a ReadableStream set as body. Fetch over HTTP/1.1, on Chromium based browsers, use Trasnfer-Encoding: chunked, when the feature flag is set to allow upload streaming over HTTP/1.1. The server is also Chromium browser, inside an Isolated Web App where Direct Sockets TCPServerSocket is defined. When the client writes to the WritableStreamDefaultWriter, one or more Uint8Arrays are received in the server, with length encoded, then the data per the linked specification.
Aug 15 at 3:42 comment added Maarten Bodewes HTTP and telnet use the same line endings as Windows; this has grown like that historically. However, I'm indicating that if you receive chunks of data then other line endings may be in there as well. I'm not sure what you are trying to accomplish. Maybe this is a way for you to read out the headers of a HTTP request. Could well be the case, don't know why you should chunk that or why you would look for that as you haven't explained. But hey, I guess you're golden, as you seem to be understanding what you're doing, right? That's all a program really needs.
Aug 15 at 2:17 comment added guest271314 If you don't understand what's going on, maybe you shouldn't have answered the question? I'm parsing Transfer-Encoding: chunked data that is read in the server as a series of Uint8Arrays, inside Chromium browser. The server is TCPServerSocket. Here's the specification datatracker.ietf.org/doc/html/rfc9112#name-transfer-encoding. The question has nothing to do with Windows.
Aug 15 at 0:21 history answered Maarten Bodewes CC BY-SA 4.0