Menu
Home
Blog
Add-ons
Forum
Wiki
Developers
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
dependencies
vendor
mozjshttpd
test
test_body_length.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>
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
40
/*
41
* Tests that the Content-Length header in incoming requests is interpreted as
42
* a decimal number, even if it has the form (including leading zero) of an
43
* octal number.
44
*/
45
46
const
PORT
= 4444;
47
48
var
srv
;
49
50
function
run_test
()
51
{
52
srv
=
createServer
();
53
srv
.registerPathHandler(
"/content-length"
,
contentLength
);
54
srv
.start(
PORT
);
55
56
runHttpTests
(
tests
,
testComplete
(
srv
));
57
}
58
59
const
REQUEST_DATA
=
"12345678901234567"
;
60
61
function
contentLength
(request, response)
62
{
63
do_check_eq
(request.method,
"POST"
);
64
do_check_eq
(request.getHeader(
"Content-Length"
),
"017"
);
65
66
var body =
new
ScriptableInputStream
(request.bodyInputStream);
67
68
var avail;
69
var
data
=
""
;
70
while
((avail = body.available()) > 0)
71
data += body.read(avail);
72
73
do_check_eq
(data,
REQUEST_DATA
);
74
}
75
76
/***************
77
* BEGIN TESTS *
78
***************/
79
80
var
tests
= [
81
new
Test
(
"http://localhost:4444/content-length"
,
82
init_content_length
),
83
];
84
85
function
init_content_length
(ch)
86
{
87
var content =
Cc
[
"@mozilla.org/io/string-input-stream;1"
]
88
.createInstance(
Ci
.nsIStringInputStream);
89
content.data =
REQUEST_DATA
;
90
91
ch.QueryInterface(
Ci
.nsIUploadChannel)
92
.setUploadStream(content,
"text/plain"
,
REQUEST_DATA
.length);
93
94
// Override the values implicitly set by setUploadStream above.
95
ch.requestMethod =
"POST"
;
96
ch.setRequestHeader(
"Content-Length"
,
"017"
,
false
);
// 17 bytes, not 15
97
}
Cc
const Cc
Definition:
sbCoverHelper.jsm:27
do_check_eq
do_check_eq(typeof PlacesUtils,"object")
init_content_length
function init_content_length(ch)
Definition:
test_body_length.js:85
contentLength
function contentLength(request, response)
Definition:
test_body_length.js:61
runHttpTests
function runHttpTests(testArray, done)
Definition:
head_utils.js:340
tests
var tests
Definition:
test_body_length.js:80
run_test
function run_test()
Definition:
test_body_length.js:50
REQUEST_DATA
const REQUEST_DATA
Definition:
test_body_length.js:59
createServer
function createServer()
Definition:
head_utils.js:53
testComplete
function testComplete(srv)
Definition:
head_utils.js:292
Test
function Test(path, initChannel, onStartRequest, onStopRequest)
Definition:
head_utils.js:322
Ci
const Ci
Definition:
sbCoverHelper.jsm:28
ScriptableInputStream
const ScriptableInputStream
Definition:
httpd.js:216
data
observe data
Definition:
FeedWriter.js:1329
srv
var srv
Definition:
test_body_length.js:48
PORT
const PORT
Definition:
test_body_length.js:46