apiaryio / http-string-parser Goto Github PK
View Code? Open in Web Editor NEWParse HTTP Request and Response from String in Node.JS
License: MIT License
Parse HTTP Request and Response from String in Node.JS
License: MIT License
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>
{
protocolVersion: undefined,
statusCode: undefined,
statusMessage: undefined,
headers: {},
body: ''
}
It'd be nice if it had Typescript typings. Here's a start in case anyone else needs them:
declare module 'http-string-parser' {
export interface HttpStringParserResult {
protocolVersion: string
statusCode: string
statusMessage: string
headers: { [key: string]: string }
body: string
}
function parseRequest(requestString: string): HttpStringParserResult
function parseRequestLine(requestLine: string): HttpStringParserResult
function parseResponse(responseString: string): HttpStringParserResult
function parseStatusLine(statusLine: string): HttpStringParserResult
function parseHeaders(headersLinesArray: string[]): HttpStringParserResult
}
Parsing this response
HTTP/1.1 200 OK
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Security-Policy: script-src 'self'
Strict-Transport-Security: max-age=31536000
Set-Cookie: JSESSIONID=1AF9A42DC89C0CD2620ECE5449074DF1.PPM1-1; Path=/itg/; HttpOnly
Set-Cookie: JSESSIONID=1AF9A42DC89C0CD2620ECE5449074DF1.PPM1-1; path=/itg; HTTPOnly
Accept-Language: ru_RU
Cache-Control: no-cache, post-check=0, pre-check=0
Content-Type: text/html;charset=UTF-8
Transfer-Encoding: chunked
Date: Wed, 25 Oct 2017 12:57:35 GMT
Server:
produce result without second Set-Cookie
header
{
'X-Frame-Options': 'SAMEORIGIN',
'X-XSS-Protection': '1; mode=block',
'X-Content-Security-Policy': 'script-src \'self\'',
'Strict-Transport-Security': 'max-age=31536000',
'Set-Cookie': 'JSESSIONID=1AF9A42DC89C0CD2620ECE5449074DF1.PPM1-1; path=/itg; HTTPOnly',
'Accept-Language': 'ru_RU',
'Cache-Control': 'no-cache, post-check=0, pre-check=0',
'Content-Type': 'text/html;charset=UTF-8',
'Transfer-Encoding': 'chunked',
Date: 'Wed, 25 Oct 2017 12:57:35 GMT',
Server: ''
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.