Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Fails parsing request #4

Open
SunboX opened this issue Jun 11, 2015 · 4 comments
Open

Fails parsing request #4

SunboX opened this issue Jun 11, 2015 · 4 comments

Comments

@SunboX
Copy link

SunboX commented Jun 11, 2015

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: ''
}
@SunboX
Copy link
Author

SunboX commented Jun 11, 2015

@SunboX
Copy link
Author

SunboX commented Jun 11, 2015

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;
};

@netmilk
Copy link
Contributor

netmilk commented Jun 11, 2015

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

@SunboX
Copy link
Author

SunboX commented Jun 11, 2015

Hi Adam, yes I'm using it together with https://github.com/jasmine/jasmine-ajax
I can do a pull request, no prob.

This was referenced Jun 11, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants