[webkit-gtk] Send HTTP header line for every request

Jay Strict jay.strict at posteo.de
Sat Jun 25 08:50:23 PDT 2016


Hello list,

I am the author of a Gnome Shell extension [1] that uses WebKitGTK2 for
rendering a WebView for a locally running Syncthing daemon.

The extension uses gobject introspection with the GJS bindings to
WebKitGTK2.
To authenticate to the daemon, the client has to provide an HTTP header
(named "X-API-Key") for every HTTP message it sends. Currenctly I use
the following code to send the header line:
======================================================================
    let request = WebKit2.URIRequest.new(uri);
    if (this.apikey) {
        let headers = request.get_http_headers();
        headers.append('X-API-Key', this.apikey);
    }
    this._webView.load_request(request);
======================================================================

This works for the very first request, where the URL is
"http://localhost/". But internally, WebKit2 parses the HTML file and
tries to fetch all the resources that are references therein (all .js
files, images, etc.). In the request for those resources, the X-API-Key
header line is missing. (See [2] for more information.)

I would like to add the header line to *all* requests. How do I do that?

I assume, as of [3], that I have to implement a WebExtension, but I
don't know how to do that, or if it is even possible in Javascript.
There is a Javascript function
WebKit2.WebContext.set_web_extensions_directory(directory: String)
but I am not sure what that is for. Can it also be used to implement a
WebExtension in Javascript?


Thank you for your help
Jay


[1] https://github.com/jaystrictor/gnome-shell-extension-syncthing
[2] https://forum.syncthing.net/t/api-key-for-webview-does-not-work/7695
[3] http://stackoverflow.com/a/21997744


More information about the webkit-gtk mailing list