Can't get nsIHttpChannel when response is image

RESOLVED INVALID

Status

()

Core
ImageLib
RESOLVED INVALID
11 years ago
11 years ago

People

(Reporter: Glenn Boysko, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(4 attachments)

(Reporter)

Description

11 years ago
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?
(Reporter)

Comment 2

11 years ago
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.
what's aRequest.name?
(Reporter)

Comment 4

11 years ago
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?
(Reporter)

Comment 6

11 years ago
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?
(Reporter)

Comment 7

11 years ago
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...
(Reporter)

Comment 9

11 years ago
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?
(Reporter)

Comment 11

11 years ago
I haven't written an XPCOM component, but I'll see what I can do...
(Reporter)

Comment 12

11 years ago
Created attachment 274496 [details]
Main HTML Page to turn on XPCOM component.
(Reporter)

Comment 13

11 years ago
Created attachment 274497 [details]
TestImageLoad IDL file for nsITestImageLoad interface
(Reporter)

Comment 14

11 years ago
Created attachment 274498 [details]
TestLoadImage XPCOM Component in JavaScript
(Reporter)

Comment 15

11 years ago
Created attachment 274499 [details]
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
Last Resolved: 11 years ago
Component: Networking: HTTP → ImageLib
QA Contact: networking.http → imagelib
Resolution: --- → INVALID
(Reporter)

Comment 18

11 years ago
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
Last Resolved: 11 years ago11 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.