Skip to content

[webview_flutter_web][MIME] Incorrect parsing mime type #118090

@SERDUN

Description

@SERDUN

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listp: webviewThe WebView pluginpackageflutter/packages repository. See also p: labels.platform-webWeb applications specificallyr: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions