WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED WONTFIX
Bug 160432
XHR Remove Headers
https://bugs.webkit.org/show_bug.cgi?id=160432
Summary
XHR Remove Headers
marc
Reported
2016-08-01 16:18:55 PDT
This is not really a bug but more of a feature request, or rather explanation of missing feature request. Why can't I as a developer choose what to send to my own server with XHR? I need to remove User-Agent, Referer, Accept-Encoding, Accept-Language and Connection headers to save bandwidth.
Attachments
Add attachment
proposed patch, testcase, etc.
youenn fablet
Comment 1
2016-08-01 23:28:40 PDT
XHR is a rather high level API that works well in most cases but lacks some flexibility. You might want to look at the fetch API which gives more flexibility to the web developper. For instance, with the fetch API, there is an option to control the referrer. To be noted though that some headers cannot be let under the control of the web application for security purposes. I don't think that there is a way to remove all headers you want with the fetch API. That said, HTTP/2 uses HPACK for header representation and for the headers you are mentioning (except referer), it will be very good at representing them in a few bytes. So my suggestion would be to migrate to HTTP/2 and start using the fetch API wherever available.
marc
Comment 2
2016-08-02 11:06:09 PDT
What are those security purposes? I'm connecting to my own server.
marc
Comment 3
2016-08-06 06:11:34 PDT
Ok, so how can I submit a pull request? I just need this edit in class XMLHttpRequest.cpp and method XMLHttpRequest::setRequestHeader: if(m_sameOriginRequest && value == null) m_requestHeaders.remove(name) before this comment: // A privileged script (e.g. a Dashboard widget) can set any headers.
marc
Comment 4
2016-08-06 06:24:25 PDT
Maybe this is better: if(m_sameOriginRequest && value.length() == 0) { m_requestHeaders.remove(name) return; } Just google "remove header XHR" to see why those 4 lines would be a great addition to webkit.
youenn fablet
Comment 5
2016-08-10 16:32:42 PDT
What you propose may just remove headers that the web app previously set. It will not remove the headers that lower layers of WebKit will set. Before uploading a patch here, it might be better to file an issue at whatwg xhr github.
marc
Comment 6
2016-08-11 04:17:55 PDT
Ok, can you point me to the code that would remove headers? I have started a discussion over at github too:
https://github.com/whatwg/xhr/issues/83
marc
Comment 7
2016-08-18 23:14:03 PDT
So whatwg could not help with XHR. I filed a issue for fetch. But I really think this is needed so much it would make sense to add it to XHR too. What are the details of getting these headers removed? Can you point me to some places in the source?
youenn fablet
Comment 8
2016-08-19 01:41:08 PDT
The simplest approach might be to grep the code for - addHTTPHeaderField - HTTPHeaderName:: You will find places like CachedResource (for referrer and origin), DocumentThreadableLoader, CachedResourceLoader, ResourceLoader. Other headers might be specified in WebKit platform a specific code (see soup, cf code). Non-WebKit code my also update headers: HTTP libraries, browser a specific code. If you are building your app with a browser, one solution may be a local proxy between your client and server. If you are using a WebView, there may be callbacks that may allow you to inspect and modify requests before sending them.
youenn fablet
Comment 9
2016-08-19 01:47:16 PDT
Or using WebSocket...
Anne van Kesteren
Comment 10
2023-03-27 08:16:28 PDT
We generally don't want to add new functionality to XMLHttpRequest.
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug