@@ -5,6 +5,7 @@ var sys = require("util")
55 , http = require ( "http" ) ;
66
77// Test server
8+ /*
89var server = http.createServer(function (req, res) {
910 var body = "Hello World";
1011 res.writeHead(200, {
@@ -17,27 +18,62 @@ var server = http.createServer(function (req, res) {
1718
1819 this.close();
1920}).listen(8000);
21+ */
2022
2123// Test request methods that aren't allowed
2224try {
2325 xhr . open ( "TRACK" , "http://localhost:8000/" ) ;
24- } catch ( e ) {
25- console . log ( "Exception for TRACK" , e ) ;
26- }
26+ console . log ( "ERROR: TRACK should have thrown exception" ) ;
27+ } catch ( e ) { }
2728try {
2829 xhr . open ( "TRACE" , "http://localhost:8000/" ) ;
29- } catch ( e ) {
30- console . log ( "Exception for TRACE" , e ) ;
31- }
30+ console . log ( "ERROR: TRACE should have thrown exception" ) ;
31+ } catch ( e ) { }
3232try {
3333 xhr . open ( "CONNECT" , "http://localhost:8000/" ) ;
34- } catch ( e ) {
35- console . log ( "Exception for CONNECT" , e ) ;
36- }
34+ console . log ( "ERROR: CONNECT should have thrown exception" ) ;
35+ } catch ( e ) { }
3736// Test valid request method
3837try {
3938 xhr . open ( "GET" , "http://localhost:8000/" ) ;
40- console . log ( "GET request allowed" ) ;
4139} catch ( e ) {
42- console . log ( "Invalid exception for GET" , e ) ;
40+ console . log ( "ERROR: Invalid exception for GET" , e ) ;
4341}
42+
43+ // Test forbidden headers
44+ var forbiddenRequestHeaders = [
45+ "accept-charset" ,
46+ "accept-encoding" ,
47+ "access-control-request-headers" ,
48+ "access-control-request-method" ,
49+ "connection" ,
50+ "content-length" ,
51+ "content-transfer-encoding" ,
52+ "cookie" ,
53+ "cookie2" ,
54+ "date" ,
55+ "expect" ,
56+ "host" ,
57+ "keep-alive" ,
58+ "origin" ,
59+ "referer" ,
60+ "te" ,
61+ "trailer" ,
62+ "transfer-encoding" ,
63+ "upgrade" ,
64+ "user-agent" ,
65+ "via"
66+ ] ;
67+
68+ for ( var i in forbiddenRequestHeaders ) {
69+ try {
70+ xhr . setRequestHeader ( forbiddenRequestHeaders [ i ] , "Test" ) ;
71+ console . log ( "ERROR: " + forbiddenRequestHeaders [ i ] + " should have thrown exception" ) ;
72+ } catch ( e ) {
73+ }
74+ }
75+
76+ // Try valid header
77+ xhr . setRequestHeader ( "X-Foobar" , "Test" ) ;
78+
79+ console . log ( "Done" ) ;
0 commit comments