-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[webview_flutter] Webiew post url support #1970
Conversation
I would like to ask e2e test but that would require adding support for POST headers to |
(Haven't reviewed yet, just replying on your testing comment:) What I'd really want to experiment with is launching a local HTTP server as part of the test, this would have unblocked other scenarios we couldn't test as well. It may as well be too much out of scope for this PR though. |
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.
Thanks left a few comments, as said we would need an e2e test before this can land.
@@ -135,6 +149,20 @@ public void onMethodCall(MethodCall methodCall, Result result) { | |||
} | |||
} | |||
|
|||
private static String initialParametersToString(Map<String, Object> parameters) |
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.
Expecting a Map -> application/x-www-form-urlencoded
encoding in each platform implementation sounds a little fragile in case these implementations don't exactly match.
My preference would be to take a similar approach to Android's WebView and WkWebView where the encoding is the responsibility of the app developer, which allows some more flexibility for developers.
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 think this is how you're suppose to do that, webview send form by post with this.
NSMutableString* resultString = [NSMutableString string]; | ||
for (NSString* key in [params allKeys]) { | ||
if ([resultString length] > 0) [resultString appendString:@"&"]; | ||
[resultString appendFormat:@"%@=%@", key, [params objectForKey:key]]; |
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.
These values would have to be url encoded as well to match the Android implementation.
Anyway as mentioned in previous comment I think we better not make this the responsibility of the platform 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.
I changed implementation so developer can send encoded string by himself
[request setHTTPMethod:@"POST"]; | ||
[request setHTTPBody:postData]; | ||
[request setValue:contentLength forHTTPHeaderField:@"Content-Length"]; | ||
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; |
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.
Seems like the Android webview forces this encoding, do you know if multipart/form-data
is allowed with WkWebView?
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 know if you can send multipart like that, but code I've seen uses form encoded only
@@ -134,6 +134,7 @@ class WebView extends StatefulWidget { | |||
Key key, | |||
this.onWebViewCreated, | |||
this.initialUrl, | |||
this.initialPostParameters, |
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 think we better start with a WebViewController.postUrl
which covers the more generic use case (posting at any point). The initialUrl
is a convenience mechanism for simple cases, I'd be hesitant to add complexity to it.
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.
Moved method to controller as suggested :)
Thank you for review, need to prepare for presentation now, but will come back to it in 2 weeks. |
Moved encoding to client side
772ae65
to
27260e0
Compare
It took me longer than I thought it would. Sorry for delay. Still I don't have e2e test for that, would it be possible to add endpoint to server? |
We apologize for the long delay in triaging this PR. We’re in the process of overhauling our PR triage system to respond much more quickly, as well as working through the backlog. Can you clarify your last question? What server are you wanting to add an endpoint to? (I suspect the best way to unblock an end-to-end test here would be a local webserver as discussed above, but if there are other options we can certainly explore them.) |
@stuartmorgan That was some time ago but as far as I remeber, I wanted to write test to check if webview actually make that POST request. My idea was to integration test to this server https://github.com/flutter/plugins/blob/master/packages/webview_flutter/example/integration_test/webview_flutter_test.dart#L95 and check if it returns different response for POST |
@iskakaushik Do you know what https://flutter-header-echo.herokuapp.com/ is? Do we own it? It seems problematic to have our integration test depending on a service that we don't have a clearly documented handling of (ownership, update process, etc.). I'm curious if there is a reason we did that originally vs. using a local server. |
@stuartmorgan I tried to start dart http server inside test but from what I find, you'd have to run it in different isolate and that's not possible to do when test run |
@iskakaushik Ping on the server question above? |
Can you elaborate on this? I.e., do you have docs or other resources to link to? (I'm just not familiar with this restriction, and would like to investigate further.) |
@stuartmorgan sorry for long reply, checked if I have my old code but it's lost. I checked flutter issues and other people have the same problems with isolates in flutter driver tests: flutter/flutter#24703 |
It sounds like it wouldn't have worked as an isolate at the time the server was added. If that's no longer the case though, and we can make this self-contained, that would be far better than having an outside server; we're seeing here the issues with the server approach, where it's non-obvious how to update the one that's there (or even whether we still can). |
makes sense. I will check if that's still an issue (PR is quite old) and come back with the results. |
@charafau Are you still planning on moving forward with this? |
@stuartmorgan I completely forgot about it. I don't have time right now so I will leave the issue to implement for someone else. |
I'm going to close this and leave a note on the issue; if anyone wants to pick this back up please don't hesitate to do so. |
Description
Added initial post parameters - first request to the webpage will be POST request
Related Issues
flutter/flutter#27730
flutter/flutter#29930
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]
). This will ensure a smooth and quick review process.///
).flutter analyze
) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?