Adding custom header to request

Add-in Express™ Support Service
That's what is more important than anything else

Adding custom header to request
 
George Stavrev




Posts: 17
Joined: 2011-06-30
Hello,

I am trying to add a custom header to all outgoing requests (eventually it will be all outgoing requests to a specific domain and it will contain the add in version number). Unfortunately I haven't had much luck getting it working. I have read through http://www.add-in-express.com/forum/read.php?PAGEN_1=1&FID=10&TID=9744#nav_start, but I wasn't able to pick out what might be going wrong.

This is in my code, trying a few different things out:


        private void IEModule_BeforeNavigate2(ADXIEBeforeNavigate2EventArgs e)
        {
            e.Headers = "BN-Header: foo 
";
            //e.Headers += "BN-Header: foo 
";
            //e.Headers += "BN-Header: foo";
            MessageBox.Show("adding bn-header");
        }

        private void IEModule_OnRequest_1(object sender, ADXIERequestEventArgs e)
        {
            e.AdditionalHeaders.Insert(0, "OR-Header: bar 
");
            //e.AdditionalHeaders.Insert(0, "OR-Header: bar");
            MessageBox.Show("adding or-header");
        }


I observe the MessageBox, but using Fiddler and the developer bar, I don't see the header being set. Furthermore, I also have the HandleHTTPNegotiations set to true.

Would anyone have any ideas on what I am missing?

Thank you,

-George
Posted 05 Aug, 2013 18:44:40 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi George,

There is a bug in the IE object model. To pass a custom header in the BeforeNavigate2 event you need to stop the navigation (via the Stop method) and then re-navigate the web page using the Navigate2 method with the custom header. As to the 'OnRequest' event, please try to change the code as shown below:

private void IEModule_OnRequest(object sender, ADXIERequestEventArgs e)
{
if (!e.AdditionalHeaders.EndsWith("\r\n"))
e.AdditionalHeaders += "\r\n";
e.AdditionalHeaders += "OR-Header: bar";
}
Posted 06 Aug, 2013 07:53:18 Top
George Stavrev




Posts: 17
Joined: 2011-06-30
Thanks Sergey!

I actually had to change the header addition to have the new line termination as well since it was getting bundled with some other ones.


private void IEModule_OnRequest(object sender, ADXIERequestEventArgs e) 
{ 
    if (!e.AdditionalHeaders.EndsWith("
")) 
    e.AdditionalHeaders += "
"; 
    e.AdditionalHeaders += "OR-Header: bar
"; 
}


This works well, but I was expecting it to trigger on page refresh and any other request coming from the page. Looking around these forums and the IE BHO forums, there doesn't seem to be an easy way to do that. Would you have any insight on how this could be done? I need to be able to add a header to all requests that come out from a specific page.

Thank you,

-George
Posted 07 Aug, 2013 12:01:35 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi George,

IE add-ons can't intersept all requests. So I think it is not possible to implement.
Posted 08 Aug, 2013 05:41:48 Top