Merge pull request #2626 from pine613/feature/http-string-parser

Add http-string-parser
This commit is contained in:
Masahiro Wakame
2014-08-06 00:21:21 +09:00
3 changed files with 81 additions and 0 deletions

View File

@@ -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))

View File

@@ -0,0 +1,42 @@
/// <reference path="http-string-parser.d.ts" />
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");
}

View File

@@ -0,0 +1,38 @@
// Type definitions for http-string-parser
// Project: https://github.com/apiaryio/http-string-parser
// Definitions by: MIZUNE Pine <https://github.com/pine613>
// 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 };
}