Skip to content

Commit

Permalink
StringResource: test 405 Method Not Allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
awwright committed Oct 24, 2019
1 parent c2354ef commit 13d3566
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
10 changes: 10 additions & 0 deletions test/StringResource.test.js
Expand Up @@ -122,5 +122,15 @@ describe('StringResource', function(){
assert(res.toString().match(/^HTTP\/1.1 304 /));
});
});
it('405 Method Not Allowed (PUT)', function(){
return testMessage(app, [
'PUT http://localhost/document HTTP/1.1',
'Host: localhost',
'Content-Type: text/plain',
'Content-Length: 5',
], "Foo\r\n").then(function(res){
assert(res.toString().match(/^HTTP\/1.1 405 /));
});
});
});
});
19 changes: 17 additions & 2 deletions test/util.js
Expand Up @@ -85,15 +85,30 @@ function writeMessage(server, message, body){
if(typeof body==='string' || Buffer.isBuffer(body)){
sock.clientSide.write(body);
}
// sock.serverSide.server = server;
server.emit('connection', sock.serverSide);
// server.on('clientError', function(err, socket){
// if(socket.writable){
// if(err.code === 'HPE_HEADER_OVERFLOW'){
// socket.write("HTTP/1.1 431 Request Header Fields Too Large\r\n");
// socket.write("Connection: close\r\n");
// socket.write("\r\n");
// }else{
// socket.write("HTTP/1.1 400 Client Error\r\n");
// socket.write("Connection: close\r\n");
// socket.write("\r\n");
// }
// }
// throw err;
// });
});
}

module.exports.testMessage = testMessage;
function testMessage(serverOptions, message){
function testMessage(serverOptions, message, body){
var listener = new lib.HTTPServer(serverOptions);
var server = http.createServer(listener.callback());
return writeMessage(server, message);
return writeMessage(server, message, body);
}

exports.ToJSONTransform = ToJSONTransform;
Expand Down

0 comments on commit 13d3566

Please sign in to comment.