-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
Hello, I encountered a problem with the display of the page, since the page was not displayed as text/html, but rather as text/plain.
After spending time on reproduction and searching for the problem, I came to the conclusion that the parsing of the header is not quite correct.
In the implementation:
module: webview_flutter_web
class: web_webview_controller.dart
method: loadRequest(LoadRequestParams params)
There is a tape for getting a mime
final String contentType =
httpReq.getResponseHeader('content-type') ?? 'text/html';
But according to the specification https://www.rfc-editor.org/rfc/rfc2854#section-4 we can also have a charset.
After we get the contentType we pass it as an argument to Uri.dataFromString without any parsing.
final String contentType =
httpReq.getResponseHeader('content-type') ?? 'text/html';
_webWebViewParams.iFrame.src = Uri.dataFromString(
httpReq.responseText ?? '',
mimeType: contentType,
encoding: utf8,
).toString();
As a result, if I try to render the page https://flutter.dev it will not be displayed correctly because my mime contentType="text/html; charset=utf-8".
contentType should be just "text/html"
As a solution:
final String contentType = httpReq.getResponseHeader('content-type') ?? 'text/html';
// ignore: unsafe_html
_webWebViewParams.iFrame.src = Uri.dataFromString(
httpReq.responseText ?? '',
mimeType: contentType.split(';')
encoding: utf8,
).toString();
But probably also need to use charset instead of ignoring it