Closed Bug 388518 Opened 17 years ago Closed 17 years ago

Can't get nsIHttpChannel when response is image

Categories

(Core :: Graphics: ImageLib, defect)

defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: gboysko, Unassigned)

Details

Attachments

(4 files)

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4 XPCOMViewer/0.9.5
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4 XPCOMViewer/0.9.5

I am writing a nsIWebProgressListener application which inspects an HTTP Response for specific HTTP Headers. When I encounter an onStateChange with flags STATE_STOP and STATE_IS_REQUEST, I then try to QI the aRequest object for an nsIHttpChannel interface. This works fine when the response is of type "text/html". This fails (QI fails) when the response type is "image/png". 

Reproducible: Always

Steps to Reproduce:
1.
2.
3.
Actual Results:  
aRequest.QueryInterface(Ci.nsIHttpChannel) throws exception

Expected Results:  
aRequest.QueryInterface(Ci.nsIHttpChannel) should succeed regardless of the content type. Either that or I need another way to retrieve an HTTP Response header.
Component: General → Networking: HTTP
Product: Firefox → Core
QA Contact: general → networking.http
what's aRequest.QueryInterface(Components.interfaces.nsIChannel).URI.spec in the case where QI to nsIHttpChannel fails?
When I am unable to QI for nsIHttpChannel, then the QI for nsIChannel fails as well. Here's a description of the code I used:

I have a WebProgessListener that implements onStateChange. When STATE_STOP && STATE_IS_REQUEST, I then call code which does the following:

try {
    // Get the HTTP Channel...
    var httpChannel = aRequest.QueryInterface(Ci.nsIHttpChannel);
	    		
    // Get the response header...
    var headerValue = aRequest.getResponseHeader("X-Some-Header");

    ...
} catch (e) {
    try {
        var channel = aRequest.QueryInterface(Ci.nsIChannel);
	alert("aRequest.QueryInterface(Ci.nsIChannel) is " + channel);
	alert("aRequest.QueryInterface(Ci.nsIChannel).URI is " + channel.URI);
	alert("aRequest.QueryInterface(Ci.nsIChannel).URI.spec is " + channel.URI.spec);
    } catch (e) {
	alert("Unable to get QI for nsIChannel");
    }
}

The Content-Type is image/png. The Content-Encoding is gzip. The Transfer-Encoding is chunked.
Not sure why you are referring to that, but if aRequest is an nsIRequest, then name is the name of the request, often the URI.
That's not what I meant, I meant - what is the actual value of aRequest.name in the case where the QI to nsIChannel/nsIHttpChannel fails?
Sorry for the confusion. The URL is quite long (~270 chars) and does not refer to a static image, but a dynamically generated one. There is nothing in the URL that would indicate it is an image. 

Does that explain the problem?
It appears that whether it is a dynamically generated or static image, trying to QI for nsIHttpChannel on an nsIRequest which refers to an image raises an exception.

Consider this value for aRequest.name:

http://abc-gboysko:8008/WebAbcDash/style/foobar/images/redGradientVert.jpg

Calling QI on the aRequest object for this request, as in:

var httpChannel = aRequest.QueryInterface(Ci.nsIHttpChannel);

throws this exception:

[Exception... "Component returned failure code: 0x80004002 (NS_NOINTERFACE) [nsISupports.QueryInterface]" nsresult: "0x80004002 (NS_NOINTERFACE)" location: "JS frame:: chrome://clientperf/content/monitor.js :: anonymous :: line 408" data: no]

hm... so the name does start with "http", but QI to nsIHttpChannel fails? that is odd...
This is definitely the case. Would it help to write a test case? If so, should be structured as a Firefox Add-on? Can it be made simpler and still demonstrate the problem?
yes, a testcase would help. can you make it just a js xpcom component?
I haven't written an XPCOM component, but I'll see what I can do...
Attached file TestImageLoad XPT file
Attachment #274497 - Attachment mime type: application/octet-stream → text/plain
Hmm. The object in question is the imgIRequest object (which, clearly, is not a channel). I don't think it is a bug that you get that object, but you should also get notifications about the actual channel...
OS: Windows 2000 → All
Hardware: PC → All
Ah I see. This is working as designed. For images you only get an imgIRequest, not a channel, contrary to my last comment.

(There may not always be a channel; the image may come from the image cache, etc.)
Status: UNCONFIRMED → RESOLVED
Closed: 17 years ago
Component: Networking: HTTP → ImageLib
QA Contact: networking.http → imagelib
Resolution: --- → INVALID
So, I guess my question remains: how does one read an HTTP Response Headers set on an image request?  
Status: RESOLVED → UNCONFIRMED
Resolution: INVALID → ---
you can't, sorry
Status: UNCONFIRMED → RESOLVED
Closed: 17 years ago17 years ago
Resolution: --- → INVALID
and please don't morph bugs... if you want a way to get at HTTP headers for images, file a new bug on that.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: