Skip to content

Commit

Permalink
fix: #10
Browse files Browse the repository at this point in the history
  • Loading branch information
Huachao committed Jul 19, 2016
1 parent 3e8b2af commit dc374c9
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/httpRequestParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { HttpRequest } from './models/httpRequest'
import { IRequestParser } from './models/IRequestParser'
import { RequestParserUtil } from './requestParserUtil'
import { EOL } from 'os';
import * as url from 'url';

export class HttpRequestParser implements IRequestParser {
private static defaultMethod = 'GET';
Expand Down Expand Up @@ -42,6 +43,11 @@ export class HttpRequestParser implements IRequestParser {
}
}

// if Host header provided and url is relative path, change to absolute url
if (headers['host'] && requestLine.url[0] === '/') {
requestLine.url = `http://${headers['host']}${requestLine.url}`;
}

return new HttpRequest(requestLine.method, requestLine.url, headers, body);
}

Expand Down

0 comments on commit dc374c9

Please sign in to comment.