-
Notifications
You must be signed in to change notification settings - Fork 382
Adding dart:io client #82
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
Conversation
lib/src/io_client.dart
Outdated
return request.url; | ||
} | ||
|
||
var location = redirects.last.location; |
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 I might just have to run through the array in case there was some ping ponging between servers. Not likely but certainly possible.
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 wouldn't the last location be correct?
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.
Hypothetically if you called to a.com/foo
that could redirect to another server b.com/bar
which then does a relative redirect to b.com/baz
.
I think I just need to run through the array with the lastLocation
and use that to get the final url.
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.
Can you do p.url.joinAll()
for that?
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.
@nex3 did not know about p.url.joinAll()
is that still valid with the updated implementation?
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 new implementation looks fine as-is.
lib/src/io_client.dart
Outdated
Future<StreamedResponse> send(BaseRequest request) async { | ||
var stream = request.finalize(); | ||
Future<Response> send(Request request) async { | ||
var stream = await request.read(); |
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.
await
doesn't do anything here since this is a Stream
, right?
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.
fixed
lib/src/io_client.dart
Outdated
request.headers.forEach((name, value) { | ||
ioRequest.headers.set(name, value); | ||
}); | ||
|
||
var response = await stream.pipe( | ||
DelegatingStreamConsumer.typed(ioRequest)); | ||
DelegatingStreamConsumer.typed<List<int>>(ioRequest) | ||
) as HttpClientResponse; |
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.
Rather than casting here, just await ioRequest.done
.
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.
fixed
lib/src/io_client.dart
Outdated
isRedirect: response.isRedirect, | ||
persistentConnection: response.persistentConnection, | ||
reasonPhrase: response.reasonPhrase); | ||
context: context); |
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 don't think it's correct to send the request's context back down the chain as part of the response.
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.
removed so assuming that it should just be an empty context
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.
For now, yeah.
lib/src/io_client.dart
Outdated
@@ -72,3 +73,16 @@ class IOClient extends BaseClient { | |||
_inner = null; | |||
} | |||
} | |||
|
|||
Uri _responseUrl(Request request, HttpClientResponse response) { |
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 should be part of the class, and also documented.
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.
K you want it static right? Was just following along with what we we're doing with free functions in message.dart
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.
K you want it static right?
No, as an instance method. I don't like making things static unless they have to be.
Was just following along with what we we're doing with free functions in
message.dart
Those are used in constructors, which is pretty different. Still, I might make them static methods.
lib/src/io_client.dart
Outdated
return request.url; | ||
} | ||
|
||
var location = redirects.last.location; |
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 wouldn't the last location be correct?
lib/src/io_client.dart
Outdated
var location = redirects.last.location; | ||
|
||
// Redirect can be relative or absolute | ||
return (location.isAbsolute) ? location : request.url.resolveUri(location); |
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.
Nit: unnecessary parens.
@nex3 think everything is resolved now
|
🎊 thanks @nex3 ! Onto browser_client now |
Implements a
dart:io
client with the new interface.