This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[webview_flutter_web] Avoids XHR when possible. #7090
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4275acd
update
bparrishMines 649e477
Request body must be empty too to skip XHR request. Add test.
ditman 6e20ed1
Add ContentType class to parse response headers.
ditman 551da72
Use content-type in response to encode iframe contents.
ditman d97bf8c
Attempt to run integration_tests. Do they ever fail?
ditman 744dcbb
Update docs.
ditman 1c2f1e7
Set Widget styles in a way the flutter engine likes.
ditman 267d282
Add bash to codeblocks in readme.
ditman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
packages/webview_flutter/webview_flutter_web/example/run_test.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #!/usr/bin/bash | ||
| # Copyright 2013 The Flutter Authors. All rights reserved. | ||
| # Use of this source code is governed by a BSD-style license that can be | ||
| # found in the LICENSE file. | ||
|
|
||
| if pgrep -lf chromedriver > /dev/null; then | ||
| echo "chromedriver is running." | ||
|
|
||
| if [ $# -eq 0 ]; then | ||
| echo "No target specified, running all tests..." | ||
| find integration_test/ -iname *_test.dart | xargs -n1 -i -t flutter drive -d web-server --web-port=7357 --browser-name=chrome --driver=test_driver/integration_test.dart --target='{}' | ||
| else | ||
| echo "Running test target: $1..." | ||
| set -x | ||
| flutter drive -d web-server --web-port=7357 --browser-name=chrome --driver=test_driver/integration_test.dart --target=$1 | ||
| fi | ||
|
|
||
| else | ||
| echo "chromedriver is not running." | ||
| echo "Please, check the README.md for instructions on how to use run_test.sh" | ||
| fi | ||
|
|
48 changes: 48 additions & 0 deletions
48
packages/webview_flutter/webview_flutter_web/lib/src/content_type.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| /// Class to represent a content-type header value. | ||
| class ContentType { | ||
| /// Creates a [ContentType] instance by parsing a "content-type" response [header]. | ||
| /// | ||
| /// See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type | ||
| /// See: https://httpwg.org/specs/rfc9110.html#media.type | ||
| ContentType.parse(String header) { | ||
| final Iterable<String> chunks = | ||
| header.split(';').map((String e) => e.trim().toLowerCase()); | ||
|
|
||
| for (final String chunk in chunks) { | ||
| if (!chunk.contains('=')) { | ||
| _mimeType = chunk; | ||
| } else { | ||
| final List<String> bits = | ||
| chunk.split('=').map((String e) => e.trim()).toList(); | ||
| assert(bits.length == 2); | ||
| switch (bits[0]) { | ||
| case 'charset': | ||
| _charset = bits[1]; | ||
| break; | ||
| case 'boundary': | ||
| _boundary = bits[1]; | ||
| break; | ||
| default: | ||
| throw StateError('Unable to parse "$chunk" in content-type.'); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| String? _mimeType; | ||
| String? _charset; | ||
| String? _boundary; | ||
|
|
||
| /// The MIME-type of the resource or the data. | ||
| String? get mimeType => _mimeType; | ||
|
|
||
| /// The character encoding standard. | ||
| String? get charset => _charset; | ||
|
|
||
| /// The separation boundary for multipart entities. | ||
| String? get boundary => _boundary; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
packages/webview_flutter/webview_flutter_web/test/content_type_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:webview_flutter_web/src/content_type.dart'; | ||
|
|
||
| void main() { | ||
| group('ContentType.parse', () { | ||
| test('basic content-type (lowers case)', () { | ||
| final ContentType contentType = ContentType.parse('text/pLaIn'); | ||
|
|
||
| expect(contentType.mimeType, 'text/plain'); | ||
| expect(contentType.boundary, isNull); | ||
| expect(contentType.charset, isNull); | ||
| }); | ||
|
|
||
| test('with charset', () { | ||
| final ContentType contentType = | ||
| ContentType.parse('text/pLaIn; charset=utf-8'); | ||
|
|
||
| expect(contentType.mimeType, 'text/plain'); | ||
| expect(contentType.boundary, isNull); | ||
| expect(contentType.charset, 'utf-8'); | ||
| }); | ||
|
|
||
| test('with boundary', () { | ||
| final ContentType contentType = | ||
| ContentType.parse('text/pLaIn; boundary=---xyz'); | ||
|
|
||
| expect(contentType.mimeType, 'text/plain'); | ||
| expect(contentType.boundary, '---xyz'); | ||
| expect(contentType.charset, isNull); | ||
| }); | ||
|
|
||
| test('with charset and boundary', () { | ||
| final ContentType contentType = | ||
| ContentType.parse('text/pLaIn; charset=utf-8; boundary=---xyz'); | ||
|
|
||
| expect(contentType.mimeType, 'text/plain'); | ||
| expect(contentType.boundary, '---xyz'); | ||
| expect(contentType.charset, 'utf-8'); | ||
| }); | ||
|
|
||
| test('with boundary and charset', () { | ||
| final ContentType contentType = | ||
| ContentType.parse('text/pLaIn; boundary=---xyz; charset=utf-8'); | ||
|
|
||
| expect(contentType.mimeType, 'text/plain'); | ||
| expect(contentType.boundary, '---xyz'); | ||
| expect(contentType.charset, 'utf-8'); | ||
| }); | ||
|
|
||
| test('with a bunch of whitespace, boundary and charset', () { | ||
| final ContentType contentType = ContentType.parse( | ||
| ' text/pLaIn ; boundary=---xyz; charset=utf-8 '); | ||
|
|
||
| expect(contentType.mimeType, 'text/plain'); | ||
| expect(contentType.boundary, '---xyz'); | ||
| expect(contentType.charset, 'utf-8'); | ||
| }); | ||
|
|
||
| test('empty string', () { | ||
| final ContentType contentType = ContentType.parse(''); | ||
|
|
||
| expect(contentType.mimeType, ''); | ||
| expect(contentType.boundary, isNull); | ||
| expect(contentType.charset, isNull); | ||
| }); | ||
|
|
||
| test('unknown parameter (throws)', () { | ||
| expect(() { | ||
| ContentType.parse('text/pLaIn; wrong=utf-8'); | ||
| }, throwsStateError); | ||
| }); | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Ah, I didn't recognize this when I updated these tests. Thanks for noticing this!