Skip to content

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

Merged
merged 3 commits into from
May 24, 2017
Merged

Conversation

donny-dont
Copy link

Implements a dart:io client with the new interface.

return request.url;
}

var location = redirects.last.location;
Copy link
Author

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.

Copy link
Member

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?

Copy link
Author

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.

Copy link
Member

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?

Copy link
Author

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?

Copy link
Member

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.

Future<StreamedResponse> send(BaseRequest request) async {
var stream = request.finalize();
Future<Response> send(Request request) async {
var stream = await request.read();
Copy link
Member

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?

Copy link
Author

Choose a reason for hiding this comment

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

fixed

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

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.

Copy link
Author

Choose a reason for hiding this comment

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

fixed

isRedirect: response.isRedirect,
persistentConnection: response.persistentConnection,
reasonPhrase: response.reasonPhrase);
context: context);
Copy link
Member

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.

Copy link
Author

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

Copy link
Member

Choose a reason for hiding this comment

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

For now, yeah.

@@ -72,3 +73,16 @@ class IOClient extends BaseClient {
_inner = null;
}
}

Uri _responseUrl(Request request, HttpClientResponse response) {
Copy link
Member

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.

Copy link
Author

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

Copy link
Member

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.

return request.url;
}

var location = redirects.last.location;
Copy link
Member

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?

var location = redirects.last.location;

// Redirect can be relative or absolute
return (location.isAbsolute) ? location : request.url.resolveUri(location);
Copy link
Member

Choose a reason for hiding this comment

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

Nit: unnecessary parens.

@donny-dont
Copy link
Author

@nex3 think everything is resolved now

:shipit: ?

@nex3 nex3 merged commit 11fca7b into dart-lang:master May 24, 2017
@donny-dont donny-dont deleted the feature/io-client branch May 24, 2017 22:56
@donny-dont
Copy link
Author

🎊 thanks @nex3 ! Onto browser_client now

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

3 participants