diff --git a/test/parallel/test-http-parser.js b/test/parallel/test-http-parser.js index f0a525cda3cf0b..efffbc63f231d5 100644 --- a/test/parallel/test-http-parser.js +++ b/test/parallel/test-http-parser.js @@ -27,7 +27,6 @@ const binding = process.binding('http_parser'); const methods = binding.methods; const HTTPParser = binding.HTTPParser; -const CRLF = '\r\n'; const REQUEST = HTTPParser.REQUEST; const RESPONSE = HTTPParser.RESPONSE; @@ -92,7 +91,7 @@ function expectBody(expected) { // Simple request test. // { - const request = Buffer.from(`GET /hello HTTP/1.1${CRLF}${CRLF}`); + const request = Buffer.from('GET /hello HTTP/1.1\r\n\r\n'); const onHeadersComplete = (versionMajor, versionMinor, headers, method, url, statusCode, statusMessage, @@ -129,11 +128,12 @@ function expectBody(expected) { // { const request = Buffer.from( - 'HTTP/1.1 200 OK' + CRLF + - 'Content-Type: text/plain' + CRLF + - 'Content-Length: 4' + CRLF + - CRLF + - 'pong'); + 'HTTP/1.1 200 OK\r\n' + + 'Content-Type: text/plain\r\n' + + 'Content-Length: 4\r\n' + + '\r\n' + + 'pong' + ); const onHeadersComplete = (versionMajor, versionMinor, headers, method, url, statusCode, statusMessage, @@ -162,7 +162,7 @@ function expectBody(expected) { // { const request = Buffer.from( - `HTTP/1.0 200 Connection established${CRLF}${CRLF}`); + 'HTTP/1.0 200 Connection established\r\n\r\n'); const onHeadersComplete = (versionMajor, versionMinor, headers, method, url, statusCode, statusMessage, @@ -186,15 +186,16 @@ function expectBody(expected) { // { const request = Buffer.from( - 'POST /it HTTP/1.1' + CRLF + - 'Transfer-Encoding: chunked' + CRLF + - CRLF + - '4' + CRLF + - 'ping' + CRLF + - '0' + CRLF + - 'Vary: *' + CRLF + - 'Content-Type: text/plain' + CRLF + - CRLF); + 'POST /it HTTP/1.1\r\n' + + 'Transfer-Encoding: chunked\r\n' + + '\r\n' + + '4\r\n' + + 'ping\r\n' + + '0\r\n' + + 'Vary: *\r\n' + + 'Content-Type: text/plain\r\n' + + '\r\n' + ); let seen_body = false; @@ -233,11 +234,12 @@ function expectBody(expected) { // { const request = Buffer.from( - 'GET / HTTP/1.0' + CRLF + - 'X-Filler: 1337' + CRLF + - 'X-Filler: 42' + CRLF + - 'X-Filler2: 42' + CRLF + - CRLF); + 'GET / HTTP/1.0\r\n' + + 'X-Filler: 1337\r\n' + + 'X-Filler: 42\r\n' + + 'X-Filler2: 42\r\n' + + '\r\n' + ); const onHeadersComplete = (versionMajor, versionMinor, headers, method, url, statusCode, statusMessage, @@ -246,8 +248,8 @@ function expectBody(expected) { assert.strictEqual(versionMajor, 1); assert.strictEqual(versionMinor, 0); assert.deepStrictEqual( - headers || parser.headers, - ['X-Filler', '1337', 'X-Filler', '42', 'X-Filler2', '42']); + headers || parser.headers, + ['X-Filler', '1337', 'X-Filler', '42', 'X-Filler2', '42']); }; const parser = newParser(REQUEST); @@ -261,12 +263,13 @@ function expectBody(expected) { // { // 256 X-Filler headers - const lots_of_headers = `X-Filler: 42${CRLF}`.repeat(256); + const lots_of_headers = 'X-Filler: 42\r\n'.repeat(256); const request = Buffer.from( - 'GET /foo/bar/baz?quux=42#1337 HTTP/1.0' + CRLF + - lots_of_headers + - CRLF); + 'GET /foo/bar/baz?quux=42#1337 HTTP/1.0\r\n' + + lots_of_headers + + '\r\n' + ); const onHeadersComplete = (versionMajor, versionMinor, headers, method, url, statusCode, statusMessage, @@ -296,11 +299,12 @@ function expectBody(expected) { // { const request = Buffer.from( - 'POST /it HTTP/1.1' + CRLF + - 'Content-Type: application/x-www-form-urlencoded' + CRLF + - 'Content-Length: 15' + CRLF + - CRLF + - 'foo=42&bar=1337'); + 'POST /it HTTP/1.1\r\n' + + 'Content-Type: application/x-www-form-urlencoded\r\n' + + 'Content-Length: 15\r\n' + + '\r\n' + + 'foo=42&bar=1337' + ); const onHeadersComplete = (versionMajor, versionMinor, headers, method, url, statusCode, statusMessage, @@ -328,17 +332,18 @@ function expectBody(expected) { // { const request = Buffer.from( - 'POST /it HTTP/1.1' + CRLF + - 'Content-Type: text/plain' + CRLF + - 'Transfer-Encoding: chunked' + CRLF + - CRLF + - '3' + CRLF + - '123' + CRLF + - '6' + CRLF + - '123456' + CRLF + - 'A' + CRLF + - '1234567890' + CRLF + - '0' + CRLF); + 'POST /it HTTP/1.1\r\n' + + 'Content-Type: text/plain\r\n' + + 'Transfer-Encoding: chunked\r\n' + + '\r\n' + + '3\r\n' + + '123\r\n' + + '6\r\n' + + '123456\r\n' + + 'A\r\n' + + '1234567890\r\n' + + '0\r\n' + ); const onHeadersComplete = (versionMajor, versionMinor, headers, method, url, statusCode, statusMessage, @@ -369,14 +374,15 @@ function expectBody(expected) { // { let request = Buffer.from( - 'POST /it HTTP/1.1' + CRLF + - 'Content-Type: text/plain' + CRLF + - 'Transfer-Encoding: chunked' + CRLF + - CRLF + - '3' + CRLF + - '123' + CRLF + - '6' + CRLF + - '123456' + CRLF); + 'POST /it HTTP/1.1\r\n' + + 'Content-Type: text/plain\r\n' + + 'Transfer-Encoding: chunked\r\n' + + '\r\n' + + '3\r\n' + + '123\r\n' + + '6\r\n' + + '123456\r\n' + ); const onHeadersComplete = (versionMajor, versionMinor, headers, method, url, statusCode, statusMessage, @@ -402,13 +408,14 @@ function expectBody(expected) { parser.execute(request, 0, request.length); request = Buffer.from( - '9' + CRLF + - '123456789' + CRLF + - 'C' + CRLF + - '123456789ABC' + CRLF + - 'F' + CRLF + - '123456789ABCDEF' + CRLF + - '0' + CRLF); + '9\r\n' + + '123456789\r\n' + + 'C\r\n' + + '123456789ABC\r\n' + + 'F\r\n' + + '123456789ABCDEF\r\n' + + '0\r\n' + ); parser.execute(request, 0, request.length); } @@ -419,21 +426,22 @@ function expectBody(expected) { // { const request = Buffer.from( - 'POST /helpme HTTP/1.1' + CRLF + - 'Content-Type: text/plain' + CRLF + - 'Transfer-Encoding: chunked' + CRLF + - CRLF + - '3' + CRLF + - '123' + CRLF + - '6' + CRLF + - '123456' + CRLF + - '9' + CRLF + - '123456789' + CRLF + - 'C' + CRLF + - '123456789ABC' + CRLF + - 'F' + CRLF + - '123456789ABCDEF' + CRLF + - '0' + CRLF); + 'POST /helpme HTTP/1.1\r\n' + + 'Content-Type: text/plain\r\n' + + 'Transfer-Encoding: chunked\r\n' + + '\r\n' + + '3\r\n' + + '123\r\n' + + '6\r\n' + + '123456\r\n' + + '9\r\n' + + '123456789\r\n' + + 'C\r\n' + + '123456789ABC\r\n' + + 'F\r\n' + + '123456789ABCDEF\r\n' + + '0\r\n' + ); function test(a, b) { const onHeadersComplete = (versionMajor, versionMinor, headers, @@ -477,21 +485,22 @@ function expectBody(expected) { // { const request = Buffer.from( - 'POST /it HTTP/1.1' + CRLF + - 'Content-Type: text/plain' + CRLF + - 'Transfer-Encoding: chunked' + CRLF + - CRLF + - '3' + CRLF + - '123' + CRLF + - '6' + CRLF + - '123456' + CRLF + - '9' + CRLF + - '123456789' + CRLF + - 'C' + CRLF + - '123456789ABC' + CRLF + - 'F' + CRLF + - '123456789ABCDEF' + CRLF + - '0' + CRLF); + 'POST /it HTTP/1.1\r\n' + + 'Content-Type: text/plain\r\n' + + 'Transfer-Encoding: chunked\r\n' + + '\r\n' + + '3\r\n' + + '123\r\n' + + '6\r\n' + + '123456\r\n' + + '9\r\n' + + '123456789\r\n' + + 'C\r\n' + + '123456789ABC\r\n' + + 'F\r\n' + + '123456789ABCDEF\r\n' + + '0\r\n' + ); const onHeadersComplete = (versionMajor, versionMinor, headers, method, url, statusCode, statusMessage, @@ -501,8 +510,8 @@ function expectBody(expected) { assert.strictEqual(versionMajor, 1); assert.strictEqual(versionMinor, 1); assert.deepStrictEqual( - headers || parser.headers, - ['Content-Type', 'text/plain', 'Transfer-Encoding', 'chunked']); + headers || parser.headers, + ['Content-Type', 'text/plain', 'Transfer-Encoding', 'chunked']); }; let expected_body = '123123456123456789123456789ABC123456789ABCDEF'; @@ -530,20 +539,22 @@ function expectBody(expected) { // { const req1 = Buffer.from( - 'PUT /this HTTP/1.1' + CRLF + - 'Content-Type: text/plain' + CRLF + - 'Transfer-Encoding: chunked' + CRLF + - CRLF + - '4' + CRLF + - 'ping' + CRLF + - '0' + CRLF); + 'PUT /this HTTP/1.1\r\n' + + 'Content-Type: text/plain\r\n' + + 'Transfer-Encoding: chunked\r\n' + + '\r\n' + + '4\r\n' + + 'ping\r\n' + + '0\r\n' + ); const req2 = Buffer.from( - 'POST /that HTTP/1.0' + CRLF + - 'Content-Type: text/plain' + CRLF + - 'Content-Length: 4' + CRLF + - CRLF + - 'pong'); + 'POST /that HTTP/1.0\r\n' + + 'Content-Type: text/plain\r\n' + + 'Content-Length: 4\r\n' + + '\r\n' + + 'pong' + ); const onHeadersComplete1 = (versionMajor, versionMinor, headers, method, url, statusCode, statusMessage, @@ -553,8 +564,8 @@ function expectBody(expected) { assert.strictEqual(versionMajor, 1); assert.strictEqual(versionMinor, 1); assert.deepStrictEqual( - headers, - ['Content-Type', 'text/plain', 'Transfer-Encoding', 'chunked']); + headers, + ['Content-Type', 'text/plain', 'Transfer-Encoding', 'chunked']); }; const onHeadersComplete2 = (versionMajor, versionMinor, headers, @@ -584,7 +595,7 @@ function expectBody(expected) { // Test parser 'this' safety // https://github.com/joyent/node/issues/6690 assert.throws(function() { - const request = Buffer.from(`GET /hello HTTP/1.1${CRLF}${CRLF}`); + const request = Buffer.from('GET /hello HTTP/1.1\r\n\r\n'); const parser = newParser(REQUEST); const notparser = { execute: parser.execute };