http-string-parser
http-string-parser copied to clipboard
Fails parsing request
Request
HTTP/1.1 200 OK
Date: Thu, 11 Jun 2015 07:56:03 GMT
Server: Apache-Coyote/1.1
X-Powered-By: Servlet/3.0; JBossAS-6
Access-Control-Allow-Origin: *
Content-Type: text/xml;charset=UTF-8
Vary: Accept-Encoding
Content-Length: 704
Keep-Alive: timeout=5, max=98
Connection: Keep-Alive
Cache-Control: no-cache
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:getMobileDevicesForRegisteredUserResponse xmlns:ns2="http://registration.xxx/">
<mobileDevice>
<id>7150</id>
<name>Telefon1</name>
<serialNumber>1234567890</serialNumber>
</mobileDevice>
<mobileDevice>
<id>7151</id>
<name>Telefon2</name>
<serialNumber>12345678901</serialNumber>
</mobileDevice>
<mobileDevice>
<id>7152</id>
<name>Telefon3</name>
<serialNumber>21D81939-3026-4CD4-8D41-50A115C65663</serialNumber>
</mobileDevice>
</ns2:getMobileDevicesForRegisteredUserResponse>
</soap:Body>
</soap:Envelope>
Request parsed
{
protocolVersion: undefined,
statusCode: undefined,
statusMessage: undefined,
headers: {},
body: ''
}
Demo
http://jsfiddle.net/SunboX/hmnf3036/4/
OK, this will work:
parseResponse = function(responseString) {
var headerLines, line, lines, parsedStatusLine, response;
response = {};
lines = responseString.replace(/\r/, '').split('\n'); // <- fix
parsedStatusLine = parseStatusLine(lines.shift());
response['protocolVersion'] = parsedStatusLine['protocol'];
response['statusCode'] = parsedStatusLine['statusCode'];
response['statusMessage'] = parsedStatusLine['statusMessage'];
headerLines = [];
while (lines.length > 0) {
line = lines.shift();
if (line === "") {
break;
}
headerLines.push(line);
}
response['headers'] = parseHeaders(headerLines);
response['body'] = lines.join('\r\n');
return response;
};
Hi @SunboX,
It's cool you're using this little library! Do I assume correctly that this snippet fixes this issue? Can you please file a pull request?
Thanks! Adam
Hi Adam, yes I'm using it together with https://github.com/jasmine/jasmine-ajax I can do a pull request, no prob.