Adding a header with the main frame's document URL

43 views
Skip to first unread message

Jason J. W. Williams

unread,
Feb 16, 2018, 3:47:40 PM2/16/18
to Chromium-dev
Hi Guys,

I'm trying to add an HTTP header to all outgoing requests that contains the URL of the main frame they're associated with. For example, if a page contains 6 images, I'd like to tag a header onto the URL requests that contains the main frame's document URL. (The header is going to be used on the proxy server side to annotate logs.)

Originally, I implemented it as a net::URLRequestInterceptor, by posting a task to the UI thread message loop in my custom URLRequestJob::Start() to grab the URL and then jumping back to the IO thread before adding it to the request and then starting the URLRequestJob. It mostly works, but there's a number of threading and null pointer issues with the approach.

It seems to me that I'd be better served just annotating the main frame URL onto the requests when they're made in the UI thread before they're submitted, rather than jumping around threads in an interceptor after the fact.

I'm struggling to find the right place to do that. 

RenderFrameImpl::WillSendRequest - This looks promising but I have a hunch this is only called for the frame's document, not any sub-resources. 

ChromeContentRendererClient::RenderThreadStarted - I've also looked at adding a sub-resource filter here.

I've spent a couple days spelunking in the cs.chromium.org, so any advice from someone with more experience on the best approach would be immensely appreciated. 

(The main reason I organized it as a URLRequestInterceptor initially was to keep it compartmentalized and minimize the changes to the main Chromium code base as much as possible.)

Thank you in advance for any help.

-J


PhistucK

unread,
Feb 17, 2018, 7:38:16 AM2/17/18
to jasonjw...@gmail.com, Chromium-dev
Just wondering, why are you not using the already existing Referer HTTP request header?
Is it because it is not always reliable (the page can control it with referrer policies)? Or because it only exposes the URL of the specific frame that renders the resource (and not the "main frame", assuming "main frame" is the top level frame)?


PhistucK

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev+unsubscribe@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAHZAEpd65F4O4TVNhwWJJTMP6LKpL0X2vUg1XiRDmqZh4STe%3DA%40mail.gmail.com.

Reply all
Reply to author
Forward
0 new messages