Search

WebView Control in VS 2012 update 1 xhr.getAllResponseHeaders returns malformed string by Justin Matthews1

Active

1
0
Sign in
to vote
Type: Bug
ID: 780714
Opened: 3/5/2013 10:41:22 AM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug

var request = new window.XMLHttpRequest();
...send request...
headers = request.getAllResponseHeaders();

Headers will look similar to "\nContent-Type: application/json\r\nCache-Control: no-cache\r\n"

From w3, the headers are separated by \r\n, the initial \n in the string is unexpected.
http://www.w3.org/TR/XMLHttpRequest/#the-getallresponseheaders()-method

Details (expand)

Visual Studio/Team Foundation Server/.NET Framework Tooling Version

Visual Studio 2012

Steps to reproduce

* Create a basic XAML app using Visual Studio 2012 Update 1. VS 2012 doesn't appear to have this issue.


* Add a new html page to the project, call it "index.html".

Replace "websitewithcorsenabledhere" in index.html with a website that returns the correct CORS header to enable the xhr request from the WebView control. ie Access-Control-Allow-Origin:'*'

* Add the below code to index.html.

* Add the page to the app via MainPage.xaml

<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <WebView x:Name="webView" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Source="ms-appx-web:///index.html"/>

    </Grid>

* Ensure that the app is given access to the internet in the manifest.

index.html code:

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
    <div style="text-align:center">
        <button type="button" id="btnGo">GO</button>
    </div>
    <div id="console"></div>

<script type="text/javascript">
    var log = {},
        divConsole = document.getElementById('console');

    log.value = [];
    log.output = function (style,args) {
        var idx = 0;
        if (args.length <= 0) {
            return;
        }

        log.value.push('<div style="width:100%;' + style + '">' + '[' + new Date().toISOString() + '] ');
        for (idx = 0; idx < args.length; idx++) {
            log.value.push(((idx > 0) ? (' , ') : ('')) + JSON.stringify(args[idx]).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;"));
        }
        log.value.push('</div>');
        divConsole.innerHTML = log.value.join('');        
    }

    log.trace = function () {
        log.output('',arguments);
    };
    log.fail = function () {
        log.output('color:red', arguments);
    }

    function sendXhr(cb) {
        var request = new window.XMLHttpRequest();
        request.onload = function () {
            cb(request);
        };
        request.onerror = function (err) {
            log.fail('Unable to load request, error,status,statusText', err, request.status, request.statusText, request.responseXML, request.response);
            cb(request);
        }
        request.onreadystatechange = function () {
            log.trace('readyState, status', request.readyState, request.status);
        }
        request.onprogress = function (progress) {
            log.trace('progress', progress);
        }
        
        request.open('GET', "http://websitewithcorsenabledhere", true);    
        request.send();
    }

    document.getElementById('btnGo').onclick = function () {
        log.trace('Sending request');
        
        sendXhr(function (request) {
            var headers;
            log.trace('Response Headers:', request.getAllResponseHeaders());
            log.trace('Response Text:', request.responseText);

            headers = request.getAllResponseHeaders().split("\r\n");

            headers.forEach(function (item) {
                if (item && (item.length > 0) && (false === /^\w+.*/.test(item))) {
                    log.fail('FAIL. The header string is not properly formatted:', item);
                }
            });
        });
    };
</script>
</body>
</html>

Product Language

English

Operating System

Windows 8

Operating System Language

English

Actual results


request.getAllResponseHeaders == "\nContent-Type: application/json\r\nCache-Control: no-cache\r\n"

Expected results

request.getAllResponseHeaders == "Content-Type: application/json\r\nCache-Control: no-cache\r\n"

Note that the initial characters are expected to be either the first alpha character of the first header or "\r\n" and not "\n"
File Attachments
File Name Submitted By Submitted On File Size  
WebViewXhrBug.zip (restricted) 3/5/2013 -
Sign in to post a comment.
Posted by Microsoft on 4/1/2013 at 9:49 AM
Continuing the conversation over email. Closing this Connect entry since it seems to be configuration-specific.
Posted by Justin Matthews1 on 3/15/2013 at 2:01 PM
Please keep this open. If you email me directly I can provide you with a server that that this can be reproduced with. So far I haven't been able to reproduce it other than that particular server.
Posted by Microsoft on 3/12/2013 at 10:12 PM
Hi Justin,

Thank you for the detailed issue report. In testing this I was unable to reproduce the issue against the test server I used. Can you tell us if this issue is occuring for you against an IIS server and if so, what version?

If I don't hear back within 4 business days, I'll go ahead and close this issue - thank you!

Jordan
Posted by Microsoft on 3/6/2013 at 1:15 AM
Thank you for submitting feedback on Visual Studio and .NET Framework. Your issue has been routed to the appropriate VS development team for investigation. We will contact you if we require any additional information.
Posted by Microsoft on 3/5/2013 at 10:51 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.