Bug 630733 - web console does not report data which the server did send (301, 302 and 303); f=rcampbell r=dolske approval2.0=dolske

This commit is contained in:
Mihai Sucan 2011-02-14 11:00:27 -08:00
Родитель 706b6de526
Коммит 49901c509f
4 изменённых файлов: 120 добавлений и 6 удалений

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

@ -152,6 +152,12 @@ const MIN_HTTP_ERROR_CODE = 400;
// The highest HTTP response code (exclusive) that is considered an error.
const MAX_HTTP_ERROR_CODE = 600;
// HTTP status codes.
const HTTP_MOVED_PERMANENTLY = 301;
const HTTP_FOUND = 302;
const HTTP_SEE_OTHER = 303;
const HTTP_TEMPORARY_REDIRECT = 307;
// The HTML namespace.
const HTML_NS = "http://www.w3.org/1999/xhtml";
@ -339,7 +345,7 @@ ResponseListener.prototype =
let data = NetUtil.readInputStreamToString(aInputStream, aCount);
if (HUDService.saveRequestAndResponseBodies &&
if (!this.httpActivity.response.bodyDiscarded &&
this.receivedData.length < RESPONSE_BODY_LIMIT) {
this.receivedData += NetworkHelper.
convertToUnicode(data, aRequest.contentCharset);
@ -356,6 +362,25 @@ ResponseListener.prototype =
onStartRequest: function RL_onStartRequest(aRequest, aContext)
{
this.request = aRequest;
// Always discard the response body if logging is not enabled in the Web
// Console.
this.httpActivity.response.bodyDiscarded =
!HUDService.saveRequestAndResponseBodies;
// Check response status and discard the body for redirects.
if (!this.httpActivity.response.bodyDiscarded &&
this.httpActivity.channel instanceof Ci.nsIHttpChannel) {
switch (this.httpActivity.channel.responseStatus) {
case HTTP_MOVED_PERMANENTLY:
case HTTP_FOUND:
case HTTP_SEE_OTHER:
case HTTP_TEMPORARY_REDIRECT:
this.httpActivity.response.bodyDiscarded = true;
break;
}
}
// Asynchronously wait for the data coming from the request.
this.setAsyncListener(this.sink.inputStream, this);
},
@ -377,7 +402,7 @@ ResponseListener.prototype =
// Retrieve the response headers, as they are, from the server.
let response = null;
for each (let item in HUDService.openResponseHeaders) {
if (item.channel === aRequest) {
if (item.channel === this.httpActivity.channel) {
response = item;
break;
}
@ -410,12 +435,10 @@ ResponseListener.prototype =
// Remove our listener from the request input stream.
this.setAsyncListener(this.sink.inputStream, null);
if (HUDService.saveRequestAndResponseBodies) {
if (!this.httpActivity.response.bodyDiscarded &&
HUDService.saveRequestAndResponseBodies) {
this.httpActivity.response.body = this.receivedData;
}
else {
this.httpActivity.response.bodyDiscarded = true;
}
if (HUDService.lastFinishedRequestCallback) {
HUDService.lastFinishedRequestCallback(this.httpActivity);

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

@ -120,6 +120,7 @@ _BROWSER_TEST_FILES = \
browser_webconsole_bug_613642_prune_scroll.js \
browser_webconsole_bug_618078_network_exceptions.js \
browser_webconsole_bug_613280_jsterm_copy.js \
browser_webconsole_bug_630733_response_redirect_headers.js \
head.js \
$(NULL)
@ -185,6 +186,7 @@ _BROWSER_TEST_PAGES = \
test-bug-603750-websocket.js \
test-bug-599725-response-headers.sjs \
test-bug-618078-network-exceptions.html \
test-bug-630733-response-redirect-headers.sjs \
$(NULL)
libs:: $(_BROWSER_TEST_FILES)

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

@ -0,0 +1,73 @@
/* vim:set ts=2 sw=2 sts=2 et: */
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*
* Contributor(s):
* Mihai Sucan <mihai.sucan@gmail.com>
*/
const TEST_URI = "http://example.com/browser/toolkit/components/console/hudservice/tests/browser/test-bug-630733-response-redirect-headers.sjs";
let lastFinishedRequests = {};
function requestDoneCallback(aHttpRequest)
{
let status = aHttpRequest.response.status.
replace(/^HTTP\/\d\.\d (\d+).+$/, "$1");
lastFinishedRequests[status] = aHttpRequest;
}
function performTest(aEvent)
{
HUDService.saveRequestAndResponseBodies = false;
HUDService.lastFinishedRequestCallback = null;
ok("301" in lastFinishedRequests, "request 1: 301 Moved Permanently");
ok("404" in lastFinishedRequests, "request 2: 404 Not found");
let headers0 = lastFinishedRequests["301"].response.header;
is(headers0["Content-Type"], "text/html",
"we do have the Content-Type header");
is(headers0["Content-Length"], 71, "Content-Length is correct");
is(headers0["Location"], "/redirect-from-bug-630733",
"Content-Length is correct");
is(headers0["x-foobar-bug630733"], "bazbaz",
"X-Foobar-bug630733 is correct");
let body = lastFinishedRequests["301"].response.body;
ok(!body, "body discarded for request 1");
let headers1 = lastFinishedRequests["404"].response.header;
ok(!headers1["Location"], "no Location header");
ok(!headers1["x-foobar-bug630733"], "no X-Foobar-bug630733 header");
body = lastFinishedRequests["404"].response.body;
isnot(body.indexOf("404"), -1,
"body is correct for request 2");
lastFinishedRequests = null;
finishTest();
}
function test()
{
addTab("data:text/html,<p>Web Console test for bug 630733");
browser.addEventListener("load", function(aEvent) {
browser.removeEventListener(aEvent.type, arguments.callee, true);
executeSoon(function() {
openConsole();
HUDService.saveRequestAndResponseBodies = true;
HUDService.lastFinishedRequestCallback = requestDoneCallback;
browser.addEventListener("load", function(aEvent) {
browser.removeEventListener(aEvent.type, arguments.callee, true);
executeSoon(performTest);
}, true);
content.location = TEST_URI;
});
}, true);
}

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

@ -0,0 +1,16 @@
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
function handleRequest(request, response)
{
var page = "<!DOCTYPE html><html><body><p>hello world! bug 630733</p></body></html>";
response.setStatusLine(request.httpVersion, "301", "Moved Permanently");
response.setHeader("Content-Type", "text/html", false);
response.setHeader("Content-Length", page.length + "", false);
response.setHeader("x-foobar-bug630733", "bazbaz", false);
response.setHeader("Location", "/redirect-from-bug-630733", false);
response.write(page);
}