Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8213541

WebView does not handle HTTP response without ContentType

    XMLWordPrintable

Details

    • web
    • x86_64
    • windows_10

    Backports

      Description

        If you try to load an URL into the WebView where the response does not specify the content-type, the Loader state switch to "cancelled".

        STEPS TO REPRODUCE (a bit technical because we want to remove headers):

        - Download Fiddler here : https://www.telerik.com/download/fiddler
        - Launch it, then click on "Rules" -> "Customize rules"
        - On the Fiddler script editor, scroll to the function "OnBeforeResponse" and modify it like that :

        static function OnBeforeResponse(oSession: Session) {
                if (m_Hide304s && oSession.responseCode == 304) {
                    oSession["ui-hide"] = "true";
                }
        if (oSession.uriContains("google") && oSession.responseCode == 200) {
        oSession["ui-color"] = "red";
        oSession.oResponse.headers.Remove("Content-Type");
        }
            }

        - Then run the class given in attachment

        EXPECTED RESULT:
        The WebView should load the google webPage and display it.

        ACTUAL RESULT:
        The WebView loader switch to "Cancelled" state.

        EXPLANATION:

        If we look at the RFC : https://tools.ietf.org/html/rfc7231#section-3.1.1.5 , we can see that the Content-type is not mandatory. Browser do display properly a webPage without Content-Type.

        If we debug, we can see that in com.sun.webkit.network.URLLoader, we enter the method "notifyDidReceiveResponse", then call the native method "twkDidReceiveResponse".
        I do not have access to the native code, but after that, the WebView is notified to switch to Cancelled mode because the response is detected as incorrect.

        WORK-AROUND:
        Currently, it's a bit difficult. A solution consists of providing a custom URLStreamHandlerFactory in URL class. Then we can provide a custom Handler that would override "openConnection" in order to retrieve the URLConnection, wrap it and delegates all methods except from "getContentType" in order to return a default content-type when null.

        Attachments

          Issue Links

            Activity

              People

                shadzic Samir Hadzic
                shadzic Samir Hadzic
                Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: