-
Notifications
You must be signed in to change notification settings - Fork 621
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
Refactor BufReader/BufWriter interfaces to be more idiomatic #444
Conversation
b60b841
to
97c67e1
Compare
A similar change could be made w.r.t the ReadResult interface, which we could change to |
also cc @kevinkassimo |
also cc @bartlomieju |
I agreed with your approach you mentioned in the original issue. I think this API is far more idiomatic Js/Ts. I haven't combed through the PR but liked what I did scan. |
I also like the proposal, though I do feel we might want to move the definition I'm slightly hesitant of |
Looks good to me. Great job! |
@ry about:
see: and used here: https://github.com/golang/go/blob/master/src/net/textproto/reader.go#L150 Not sure if really misplaced. |
I totally agree that this is more natural as JS/TS. (golang uses returning multi value pattern because it doesn't use throwing for usual error handling, and that's not the case for javascript) |
+1 from me @piscisaureus, definitely cleaner, let me know if you need help with tests. We should land this PR before landing #453 - the other PR will require extensive rebase |
return [0, 0, false]; | ||
} | ||
default: { | ||
const Big = 1000000; // arbitrary upper bound |
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 is an arbitrary upper bound for the HTTP version necessary here? Isn't HTTP/2 already binary instead of text-based, and doesn't have a status line?
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.
See golang api. It's a simple port.
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 seems out of scope for this PR to fix it, but I agree with @MarkTiedemann, this parser seems rather over-engineered.
I think we should accept "HTTP/0.9"
and /^HTTP\/1.(\d+)$/
and call it a day.
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.
SGTM
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 seems out of scope for this PR to fix it
Agreed.
I think we should accept
"HTTP/0.9"
and/^HTTP\/1.(\d+)$/
and call it a day.
I think we should accept only 0.9
, 1.0
, and 1.1
in this case. This is effectively an HTTP 1 parser. Since H2 and H3 are completely different and there's not gonna be a 1.2
version (at least not any time soon), I think we can simplify this even more. (And even if 1.3
should come out one day, we'll probably know about it in advance and can just simply add the missing case then. I'd go with YAGNI here.)
This brings up another important point (which is unimportant for this PR, however): Do we need to parse and handle version 0.9
and 1.0
differently? For example, 0.9
has different methods, such as -- and this is not a joke -- SPACEJUMP
. Are there important differences that we need to take into account? And on another related note, is anyone still using 0.9
and 1.0
? 1.1
is from 1997, 22 years old. If no one is using 0.9
and 1.0
, should we just drop support for them?
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.
Agree with all of you. Created an issue for this: #463
} | ||
|
||
export async function readRequest( | ||
bufr: BufReader | ||
): Promise<[ServerRequest, BufState]> { | ||
): Promise<ServerRequest | EOF> { |
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.
👍
encoding/test.ts
Outdated
@@ -1,3 +1,3 @@ | |||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. | |||
import "./toml_test.ts"; | |||
import "./csv_test.ts"; | |||
//import "./csv_test.ts"; |
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.
Please create separate issues for csv and ws tests to be re-enabled. Link to them here this:
// TODO(#1234) Re-enable csv test.
// import "./csv_test.ts";
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.
Since this is going to break ws
and csv
... can we temporarily create something like //bufio_old
so they can continue to work until ported over?
I'm holding all PRs in deno_std until this one lands, as it's big and complex.
If this is landed i can fix |
@zekth If you have time, can you do that preemptively? (Check out this branch, do the port, and send the diff here for @piscisaureus to include in this PR.) I think this would help us land it. Of course we still need to deal with |
Will be fixed today |
csv rewrite is done : piscisaureus#2 |
For that reason, BufReader.readFull should maybe take a number of bytes and return a subarray, instead of copying into a user-provided Uint8Array. (Note that this change can be made gradually) |
We should work towards a future where type EOF = 0;
type ReadResult = number; |
01d6c96
to
d2e3819
Compare
The one "challenge" is that I think it is still a better API, it is just going to be possible to write some unsound code where TypeScript won't help. |
@kitsonk do you think |
Tests are broken now because I re-enabled mime/multipart tests in 9605729, but there's a bug in there that I can't figure out at the moment. The other TODO item is to fix |
In strict mode, TypeScript will keep the type safety of if (readResult === EOF) {
// readResult type is `null` here
} else {
// readResult type is `number` here
} |
@kitsonk also |
@kitsonk @kevinkassimo if that's the case we can remove the EOF type and just use 0. Everyone knows that 0 means EOF anyway. I do not want |
ea92926
to
621e3bc
Compare
I think this is done. |
I wonder if there are any objections to keeping the We could define So what about just keeping it? |
A 👍 from me. It hadn't occurred to me to do that, but a symbol will always be a seperate type and not collapse, and it is also seperate at runtime too. Moving it to core make sense to me as well. |
Not sure that's universal. For example, Java's |
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.
LGTM modulo comments
io: refactor BufReader/Writer interfaces to be more idiomatic (denoland#444) Thanks Vincent Le Gofff (@zekth) for porting over the CSV implementation. Fixes: denoland#436
io: refactor BufReader/Writer interfaces to be more idiomatic (denoland#444) Thanks Vincent Le Goff (@zekth) for porting over the CSV reader implementation. Fixes: denoland#436
…nd#444) Thanks Vincent Le Goff (@zekth) for porting over the CSV reader implementation. Fixes: denoland#436
…nd/std#444) Thanks Vincent Le Goff (@zekth) for porting over the CSV reader implementation. Fixes: denoland/std#436 Original: denoland/std@0ee6334
This change adds middleware for the REST API that catches HTTP errors, as defined in the Standard Library, and returns non-HTML responses. This will make future REST API development cleaner. Currently, responses are still responding with HTML. Perhaps, the middleware is set up incorrectly.
No description provided.