File tree Expand file tree Collapse file tree 2 files changed +9
-4
lines changed
Expand file tree Collapse file tree 2 files changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -33,13 +33,15 @@ exports.XMLHttpRequest = function() {
3333
3434 // Set some default headers
3535 var defaultHeaders = {
36- "User-Agent" : "node.js " ,
36+ "User-Agent" : "node-XMLHttpRequest " ,
3737 "Accept" : "*/*" ,
3838 } ;
3939
4040 var headers = defaultHeaders ;
4141
42- // These headers are not user setable
42+ // These headers are not user setable.
43+ // The following are allowed but banned in the spec:
44+ // * user-agent
4345 var forbiddenRequestHeaders = [
4446 "accept-charset" ,
4547 "accept-encoding" ,
@@ -60,7 +62,6 @@ exports.XMLHttpRequest = function() {
6062 "trailer" ,
6163 "transfer-encoding" ,
6264 "upgrade" ,
63- "user-agent" ,
6465 "via"
6566 ] ;
6667
@@ -174,7 +175,8 @@ exports.XMLHttpRequest = function() {
174175 throw "INVALID_STATE_ERR: setRequestHeader can only be called when state is OPEN" ;
175176 }
176177 if ( ! isAllowedHttpHeader ( header ) ) {
177- throw "SYNTAX_ERR: This header is not allowed" ;
178+ console . warn ( 'Refused to set unsafe header "' + header + '"' ) ;
179+ return ;
178180 }
179181 if ( sendFlag ) {
180182 throw "INVALID_STATE_ERR: send flag is true" ;
Original file line number Diff line number Diff line change @@ -49,7 +49,10 @@ xhr.onreadystatechange = function() {
4949assert . equal ( null , xhr . getResponseHeader ( "Content-Type" ) ) ;
5050try {
5151 xhr . open ( "GET" , "http://localhost:8000/" ) ;
52+ // Valid header
5253 xhr . setRequestHeader ( "X-Test" , "Foobar" ) ;
54+ // Invalid header
55+ xhr . setRequestHeader ( "Content-Length" , 0 ) ;
5356 // Test getRequestHeader
5457 assert . equal ( "Foobar" , xhr . getRequestHeader ( "X-Test" ) ) ;
5558 xhr . send ( ) ;
You can’t perform that action at this time.
0 commit comments