-
Notifications
You must be signed in to change notification settings - Fork 362
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] ✨ Add redirects
in IOStreamedResponse
#1076
base: master
Are you sure you want to change the base?
[http] ✨ Add redirects
in IOStreamedResponse
#1076
Conversation
redirects
in IOStreamedResponse
redirects
in IOStreamedResponse
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.
Hey @AlexV525
Why are you only adding this to IOStreamedResponse
? We want the different Client
implementations to behave as similarly as possible and this approach requires that the caller cast into an implementation-specific type.
Because |
Please add redirects in IOStreamedResponse for workaround (#699) With this, we can cast and then get redirect(final) url in specific usecase. When will you add Response.uri (#699)? Http is one of most important feature in app. |
That is the next thing I'm considering. |
@natebosch this is a less-breaking version of your change #699 My concern is that making this work only for Maybe it would make sense to do a major release with #699 and possibly also:
|
Yeah a long while ago I had anticipated bundling some breaking changes and doing a major version release, but it never bubbled up to a high enough priority that I took the time to plan out the full migration story. This package requires incremental migration paths across major versions - we will need to be compatible with the same Flutter SDK version across both major versions, so that we can use the new version internally before publishing, and Flutter can wait for publish until it bumps a dependency.
I still have concerns about the fidelity of this API. (Although I don't see my comments there - was there a similar PR before?) Have we verified that if we are communicating with a server that stops reading halfway through the request it is correctly reflected in the upload progress? The web implementation looks like it can make the same promises as a supported JS API, so there shouldn't be a problem there. The VM implementation looks like it relies on there not being any caching anywhere between the user's Stream and the communicating socket, and that there is appropriate backpressure applied to the Stream. If there can be a large difference between the amount of events sent to |
+1. I would be OK with a temporary situation where the API is only available on the |
We can support How about this (your opinion would be useful here too @AlexV525):
/// The final [Uri] returned by the server after any redirects.
///
/// [finalUri] will only be `null` in certain edge cases. For example, when fetching the "about:" URL in a browser, [finalUri]
/// may be `null`.
final Uri? finalUri;
|
The redirects are still valuable for a response. I can add Meanwhile, can we push splitting basic http classes from |
I think that adding an equivalent of
I don't know what you mean. |
Fixing this in |
One of the reason I've only added this field to the |
Ah, I understand. I think that the usual approach for |
Another approach that we could define a mixins like: mixin FinalUrl on BaseResponse {
abstract Uri? finalUrl;
} Users could consume it like: void main() async {
final response = await client.get();
if (response is FinalUrl) {
doSomethingWithFinalUrl(response.finalUrl);
}
} We could define a hidden class that implements that mixin. In the next breaking release, we could add |
Interesting, the subclasses could publicly claim to support this interface which would allow the same code as adding them directly on those implementations, but also give a way to use it without a platform specific import. I'd think we wouldn't want the We might want to flesh this idea out some more and see if there are any negative implications. |
Please don't hesitate to make breaking changes. I'll try adding a new class for redirects and adding |
That would go against our general policy when developing packages ;-)
How about just for |
That would be fine too, but I don't see any strong reason to abandon this PR. |
You don't need to abandon this PR but I would start with just
|
Marking as ready for review again. |
ping @brianquinlan |
Of the clients that I know about:
|
Browser fetch can at least provide info if there was (or not) redirect and final URL at no additional cost: https://github.com/Zekfad/fetch_api/blob/master/lib/src/response/response.dart#L53 https://github.com/Zekfad/fetch_api/blob/master/lib/src/response/response.dart#L69 But manual redirect handling is expensive, as you point out it requires additional HEAD (or GET) request to retrieve final URL and forge a fake redirect response accordingly. XHR has |
I believe we should definitely provide such info to users.
That's a great suggestion. I'll take a look
Sure, will check this later. |
I'll let this be your decision but, as far as I know, we don't have an actual use case for this.
|
The request provides the ability to extract the redirections from an
IOStreamedResponse
.Contribution guidelines:
dart format
.Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.