httpChannel.setRequestHeader with httpChannel.redirectTo

835 views Asked by At

I'm having trouble with my Firefox-Addon.

With my extension, I'd like to redirect requests that match a certain pattern. So far, the redirection is working fine with

httpChannel.redirectTo()

Now I'd like to add / modify the request headers for the redirection (as explained here: https://developer.mozilla.org/en-US/docs/Setting_HTTP_request_headers )

My code so far:

console.log("start");
const {Cu,Ci} = require('chrome');
Cu.import('resource://gre/modules/Services.jsm');
var httpRequestObserver =
{
    observe: function(subject, topic, data)
    {
        var httpChannel, requestURL;
        if (topic == "http-on-modify-request") {
            httpChannel = subject.QueryInterface(Ci.nsIHttpChannel);
            requestURL = httpChannel.URI.spec;
            if (requestURL.indexOf('www.3und80.de') > -1) {

                    console.log("match url");           
                    newURL = 'http://www.genialschenken.de/';

/*This has no effect*/
httpChannel.setRequestHeader("X-Hello", "World", false);

                    console.log("redirecting...");
                    httpChannel.redirectTo(Services.io.newURI(newURL, null, null));
            }
        return;
        }
    }
};

Services.obs.addObserver(httpRequestObserver, "http-on-modify-request", false);

Sadly, the line

httpChannel.setRequestHeader("X-Hello", "World", false);

has no effect. What am I doing wrong?

Thanks in advance!

1

There are 1 answers

0
Noitidart On

From IRC:

00:58 Fallen noida: nsIChannelEventSink

00:58 Fallen and nsIInterfaceRequestor

00:59 Fallen I didn't read the link though

01:00 Fallen noida: http://mxr.mozilla.org/comm-central/source/calendar/providers/caldav/calDavCalendar.js#2828

@3und80 Let's research this more and develop an solution here.