Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[webview_flutter] Webiew post url support #1970

Closed
wants to merge 7 commits into from

Conversation

charafau
Copy link
Contributor

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.

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See [Contributor Guide]).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze) does not report any problems on my PR.
  • I read and followed the [Flutter Style Guide].
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I updated pubspec.yaml with an appropriate new version according to the [pub versioning philosophy].
  • I updated CHANGELOG.md to add a description of the change.
  • I signed the [CLA].
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • No, this is not a breaking change.

@charafau charafau requested a review from amirh as a code owner August 11, 2019 03:24
@charafau
Copy link
Contributor Author

I would like to ask e2e test but that would require adding support for POST headers to https://flutter-header-echo.herokuapp.com/ would that be possible?

@amirh
Copy link
Contributor

amirh commented Aug 15, 2019

(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.

Copy link
Contributor

@amirh amirh left a 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)
Copy link
Contributor

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.

Copy link
Contributor Author

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]];
Copy link
Contributor

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.

Copy link
Contributor Author

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"];
Copy link
Contributor

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?

Copy link
Contributor Author

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,
Copy link
Contributor

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.

Copy link
Contributor Author

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 :)

@charafau
Copy link
Contributor Author

Thank you for review, need to prepare for presentation now, but will come back to it in 2 weeks.

liang530 pushed a commit to huosdk/plugins that referenced this pull request Nov 12, 2019
@charafau charafau force-pushed the webiew_post_url_support branch from 772ae65 to 27260e0 Compare November 20, 2019 13:52
@charafau charafau requested a review from amirh November 21, 2019 23:47
@charafau
Copy link
Contributor Author

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?

@stuartmorgan stuartmorgan added the p: webview_flutter Edits files for a webview_flutter plugin label Jan 29, 2021
@stuartmorgan
Copy link
Contributor

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.)

@charafau
Copy link
Contributor Author

charafau commented Apr 8, 2021

@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

@stuartmorgan
Copy link
Contributor

@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.

@charafau
Copy link
Contributor Author

@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

@stuartmorgan
Copy link
Contributor

@iskakaushik Ping on the server question above?

@stuartmorgan
Copy link
Contributor

you'd have to run it in different isolate and that's not possible to do when test run

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.)

@charafau
Copy link
Contributor Author

charafau commented Jun 2, 2021

@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
I'm fine with adding this as isolate but I guess server is there for some reason

@stuartmorgan
Copy link
Contributor

@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
I'm fine with adding this as isolate but I guess server is there for some reason

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).

@charafau
Copy link
Contributor Author

charafau commented Jun 2, 2021

makes sense. I will check if that's still an issue (PR is quite old) and come back with the results.

@stuartmorgan
Copy link
Contributor

@charafau Are you still planning on moving forward with this?

@charafau
Copy link
Contributor Author

@stuartmorgan I completely forgot about it. I don't have time right now so I will leave the issue to implement for someone else.

@Hixie
Copy link
Contributor

Hixie commented Oct 26, 2021

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants