test_request_line_split_in_two_packets.js
Go to the documentation of this file.
1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et: */
3 /* ***** BEGIN LICENSE BLOCK *****
4  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5  *
6  * The contents of this file are subject to the Mozilla Public License Version
7  * 1.1 (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  * http://www.mozilla.org/MPL/
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is httpd.js code.
17  *
18  * The Initial Developer of the Original Code is
19  * the Mozilla Corporation.
20  * Portions created by the Initial Developer are Copyright (C) 2008
21  * the Initial Developer. All Rights Reserved.
22  *
23  * Contributor(s):
24  * Jeff Walden <jwalden+code@mit.edu> (original author)
25  *
26  * Alternatively, the contents of this file may be used under the terms of
27  * either the GNU General Public License Version 2 or later (the "GPL"), or
28  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29  * in which case the provisions of the GPL or the LGPL are applicable instead
30  * of those above. If you wish to allow use of your version of this file only
31  * under the terms of either the GPL or the LGPL, and not to allow others to
32  * use your version of this file under the terms of the MPL, indicate your
33  * decision by deleting the provisions above and replace them with the notice
34  * and other provisions required by the GPL or the LGPL. If you do not delete
35  * the provisions above, a recipient may use your version of this file under
36  * the terms of any one of the MPL, the GPL or the LGPL.
37  *
38  * ***** END LICENSE BLOCK ***** */
39 
46 const PORT = 4444;
47 
48 var srv;
49 
50 function run_test()
51 {
52  srv = createServer();
53  srv.registerPathHandler("/lots-of-leading-blank-lines",
55  srv.registerPathHandler("/very-long-request-line",
57  srv.start(PORT);
58 
60 }
61 
62 
63 /***************
64  * BEGIN TESTS *
65  ***************/
66 
67 var test, data, str;
68 var tests = [];
69 
70 
71 function veryLongRequestLine(request, response)
72 {
73  writeDetails(request, response);
74  response.setStatusLine(request.httpVersion, 200, "TEST PASSED");
75 }
76 var path = "/very-long-request-line?";
77 var gibberish = "dfsasdbfjkbnsldkjnewiunfasjkn";
78 for (var i = 0; i < 10; i++)
80 str = "GET /very-long-request-line?" + gibberish + " HTTP/1.1\r\n" +
81  "Host: localhost:4444\r\n" +
82  "\r\n";
83 data = [];
84 for (var i = 0; i < str.length; i += 50)
85  data.push(str.substr(i, 50));
87 {
88  var iter = LineIterator(data);
89 
90  // Status-Line
91  do_check_eq(iter.next(), "HTTP/1.1 200 TEST PASSED");
92 
93  skipHeaders(iter);
94 
95  // Okay, next line must be the data we expected to be written
96  var body =
97  [
98  "Method: GET",
99  "Path: /very-long-request-line",
100  "Query: " + gibberish,
101  "Version: 1.1",
102  "Scheme: http",
103  "Host: localhost",
104  "Port: 4444",
105  ];
106 
107  expectLines(iter, body);
108 }
109 test = new RawTest("localhost", PORT, data, checkVeryLongRequestLine),
110 tests.push(test);
111 
112 
113 function lotsOfLeadingBlankLines(request, response)
114 {
115  writeDetails(request, response);
116  response.setStatusLine(request.httpVersion, 200, "TEST PASSED");
117 }
118 var blankLines = "\r\n";
119 for (var i = 0; i < 14; i++)
120  blankLines += blankLines;
121 str = blankLines +
122  "GET /lots-of-leading-blank-lines HTTP/1.1\r\n" +
123  "Host: localhost:4444\r\n" +
124  "\r\n";
125 data = [];
126 for (var i = 0; i < str.length; i += 100)
127  data.push(str.substr(i, 100));
129 {
130  var iter = LineIterator(data);
131 
132  // Status-Line
133  do_check_eq(iter.next(), "HTTP/1.1 200 TEST PASSED");
134 
135  skipHeaders(iter);
136 
137  // Okay, next line must be the data we expected to be written
138  var body =
139  [
140  "Method: GET",
141  "Path: /lots-of-leading-blank-lines",
142  "Query: ",
143  "Version: 1.1",
144  "Scheme: http",
145  "Host: localhost",
146  "Port: 4444",
147  ];
148 
149  expectLines(iter, body);
150 }
151 test = new RawTest("localhost", PORT, data, checkLotsOfLeadingBlankLines),
152 tests.push(test);
function lotsOfLeadingBlankLines(request, response)
do_check_eq(typeof PlacesUtils,"object")
function checkLotsOfLeadingBlankLines(data)
function skipHeaders(iter)
Definition: head_utils.js:191
function expectLines(iter, expectedLines)
Definition: head_utils.js:142
function runRawTests(testArray, done)
Definition: head_utils.js:501
function createServer()
Definition: head_utils.js:53
function checkVeryLongRequestLine(data)
function writeDetails(request, response)
Definition: head_utils.js:172
function RawTest(host, port, data, responseCheck)
Definition: head_utils.js:476
function testComplete(srv)
Definition: head_utils.js:292
function veryLongRequestLine(request, response)
_getSelectedPageStyle s i
function LineIterator(data)
Definition: head_utils.js:115