diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 357e8105d..eebbf335d 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -125,6 +125,7 @@ All definitions files include a header with the author and editors, so at some p * [highlight.js](https://github.com/isagalaev/highlight.js) (by [Niklas Mollenhauer](https://github.com/nikeee)) * [History.js](https://github.com/browserstate/history.js) (by [Boris Yankov](https://github.com/borisyankov)) * [Html2Canvas.js](https://github.com/niklasvh/html2canvas/) (by [Richard Hepburn](https://github.com/rwhepburn)) +* [http-string-parser](https://github.com/apiaryio/http-string-parser) (by [MIZUNE Pine](https://github.com/pine613)) * [Humane.js](http://wavded.github.com/humane-js/) (by [John Vrbanac](https://github.com/jmvrbanac)) * [i18next](http://i18next.com/) (by [Maarten Docter](https://github.com/mdocter)) * [iCheck](http://damirfoy.com/iCheck/) (by [Dániel Tar](https://github.com/qcz)) diff --git a/http-string-parser/http-string-parser-test.ts b/http-string-parser/http-string-parser-test.ts new file mode 100644 index 000000000..9c4116e5d --- /dev/null +++ b/http-string-parser/http-string-parser-test.ts @@ -0,0 +1,42 @@ +/// + +import parser = require("http-string-parser"); + +function test_request(): void { + var result = parser.parseRequest("HTTP/1.1 GET /\r\nHost: www.example.com\r\n\r\n"); + + var body: string = result.body; + var headers: { [key: string]: string } = result.headers; + var method: string = result.method; + var uri: string = result.uri; +} + +function test_response(): void { + var response = parser.parseResponse("HTTP/1.1 200 OK\r\n\r\n"); + + var body: string = response.body; + var headers: { [key: string]: string } = response.headers; + var statusCode: string = response.statusCode; + var statusMessage: string = response.statusMessage; +} + +function test_requestLine(): void { + var result = parser.parseRequestLine("HTTP/1.1 GET /"); + + var method: string = result.method; + var protocol: string = result.protocol; + var uri: string = result.uri; +} + +function test_statusLine(): void { + var result = parser.parseStatusLine("HTTP/1.1 200 OK"); + + var protocol: string = result.protocol; + var statusCode: string = result.statusCode; + var statusMessage: string = result.statusMessage; +} + +function test_headers(): void { + var result: { [key: string]: string } = + parser.parseHeaders("Content-Type: text/html; charset=utf-8\r\nContent-Length: 256\r\n"); +} \ No newline at end of file diff --git a/http-string-parser/http-string-parser.d.ts b/http-string-parser/http-string-parser.d.ts new file mode 100644 index 000000000..4239cd9df --- /dev/null +++ b/http-string-parser/http-string-parser.d.ts @@ -0,0 +1,38 @@ +// Type definitions for http-string-parser +// Project: https://github.com/apiaryio/http-string-parser +// Definitions by: MIZUNE Pine +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module "http-string-parser" { + interface ParseRequestResult { + method: string; + uri: string; + headers: { [key: string]: string }; + body: string; + } + + interface ParseResponseResult { + statusCode: string; + statusMessage: string; + headers: { [key: string]: string }; + body: string; + } + + interface ParseRequestLineResult { + method: string; + uri: string; + protocol: string; + } + + interface ParseStatusLineResult { + protocol: string; + statusCode: string; + statusMessage: string; + } + + export function parseRequest(requestString: string): ParseRequestResult; + export function parseResponse(responseString: string): ParseResponseResult; + export function parseRequestLine(requestLineString: string): ParseRequestLineResult; + export function parseStatusLine(statusLine: string): ParseStatusLineResult; + export function parseHeaders(headerLines: string): { [key: string]: string }; +}