Bug 412945 - "Malformed POST requests generated when using elance.com" [r=biesi sr=bzbarsky]

This commit is contained in:
Michal Novotny 2008-10-01 00:31:24 -05:00
Родитель 19dcb32164
Коммит 876fe60344
2 изменённых файлов: 59 добавлений и 0 удалений

Просмотреть файл

@ -213,6 +213,23 @@ nsHttpTransaction::Init(PRUint8 caps,
if (requestHead->Method() == nsHttp::Head)
mNoContent = PR_TRUE;
// Make sure that there is "Content-Length: 0" header in the requestHead
// in case of POST and PUT methods when there is no requestBody and
// requestHead doesn't contain "Transfer-Encoding" header.
//
// RFC1945 section 7.2.2:
// HTTP/1.0 requests containing an entity body must include a valid
// Content-Length header field.
//
// RFC2616 section 4.4:
// For compatibility with HTTP/1.0 applications, HTTP/1.1 requests
// containing a message-body MUST include a valid Content-Length header
// field unless the server is known to be HTTP/1.1 compliant.
if ((requestHead->Method() == nsHttp::Post || requestHead->Method() == nsHttp::Put) &&
!requestBody && !requestHead->PeekHeader(nsHttp::Transfer_Encoding)) {
requestHead->SetHeader(nsHttp::Content_Length, NS_LITERAL_CSTRING("0"));
}
// grab a weak reference to the request head
mRequestHead = requestHead;

Просмотреть файл

@ -0,0 +1,42 @@
do_import_script("netwerk/test/httpserver/httpd.js");
var httpserv;
function TestListener() {
}
TestListener.prototype.onStartRequest = function(request, context) {
}
TestListener.prototype.onStopRequest = function(request, context, status) {
httpserv.stop();
do_test_finished();
}
function run_test() {
httpserv = new nsHttpServer();
httpserv.registerPathHandler("/bug412945", bug412945);
httpserv.start(4444);
// make request
var channel =
Components.classes["@mozilla.org/network/io-service;1"].
getService(Components.interfaces.nsIIOService).
newChannel("http://localhost:4444/bug412945", null, null);
channel.QueryInterface(Components.interfaces.nsIHttpChannel);
channel.requestMethod = "post";
channel.asyncOpen(new TestListener(), null);
do_test_pending();
}
function bug412945(metadata, response) {
if (!metadata.hasHeader("Content-Length") ||
metadata.getHeader("Content-Length") != "0")
{
do_throw("Content-Length header not found!");
}
}