[webkit-gtk] Finding out the HTTP method of requests (PATCH)

Jon Forsberg jon.orebro at gmail.com
Sun Nov 22 09:01:05 PST 2015


I have zero experience hacking webkit so I don't really know what I'm
doing, but this works for me. Patch is aginst webkitgtk 2.10.3.


2015-10-20 12:26 GMT+02:00 Carlos Garcia Campos <cgarcia at igalia.com>:

> El mar, 20-10-2015 a las 10:44 +0200, Jon Forsberg escribió:
> > Hello!
> > I'm using webkit2gtk to create a restricted web browser and I would
> > like to be able to choose which HTTP methods to allow (for both page
> > navigation and resource loading). For example I might want to allow
> > GET and HEAD but not POST as a way to limit interaction with web
> > pages. I have looked at the resource-load-started and decide-
> > policy signals and the WebKitWebResource, WebKitURIRequest and
> > WebKitURIResponse classes but it seems the closest you can get is a
> > SoupMessageHeaders (which contains the headers but not the method).
> > Am i missing something or is it not possible to find out the method
> > of a request?
>
> No, you aren't. It's not exposed, but it should be easy to add
> a webkit_uri_request_get_http_method() or something similar. Note that
> to block requests, you need to use a web process extension and connect
> to WebKitWebPage::send-request signal.
> Feel free to file a bug report to request this, if you can provide a
> patch it would be even better :-)
>
> > Thanks
> >
> > _______________________________________________
> > webkit-gtk mailing list
> > webkit-gtk at lists.webkit.org
> > https://lists.webkit.org/mailman/listinfo/webkit-gtk
> --
> Carlos Garcia Campos
> http://pgp.rediris.es:11371/pks/lookup?op=get&search=0xF3D322D0EC4582C3
>
>
> _______________________________________________
> webkit-gtk mailing list
> webkit-gtk at lists.webkit.org
> https://lists.webkit.org/mailman/listinfo/webkit-gtk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.webkit.org/pipermail/webkit-gtk/attachments/20151122/a1799f42/attachment.html>
-------------- next part --------------
diff -ur webkit-2.10.3.orig/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt webkit-2.10.3/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt
--- webkit-2.10.3.orig/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt	2015-10-30 14:17:20.000000000 +0100
+++ webkit-2.10.3/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt	2015-11-22 10:46:28.007740896 +0100
@@ -462,6 +462,7 @@
 webkit_uri_request_new
 webkit_uri_request_get_uri
 webkit_uri_request_set_uri
+webkit_uri_request_get_http_method
 webkit_uri_request_get_http_headers
 
 <SUBSECTION Standard>
diff -ur webkit-2.10.3.orig/Source/WebKit2/UIProcess/API/gtk/WebKitURIRequest.cpp webkit-2.10.3/Source/WebKit2/UIProcess/API/gtk/WebKitURIRequest.cpp
--- webkit-2.10.3.orig/Source/WebKit2/UIProcess/API/gtk/WebKitURIRequest.cpp	2015-10-30 14:17:20.000000000 +0100
+++ webkit-2.10.3/Source/WebKit2/UIProcess/API/gtk/WebKitURIRequest.cpp	2015-11-22 11:25:47.035768460 +0100
@@ -48,6 +48,7 @@
 struct _WebKitURIRequestPrivate {
     WebCore::ResourceRequest resourceRequest;
     CString uri;
+    CString http_method;
     GUniquePtr<SoupMessageHeaders> httpHeaders;
 };
 
@@ -171,6 +172,24 @@
     return request->priv->httpHeaders.get();
 }
 
+/**
+ * webkit_uri_request_get_http_method:
+ * @request: a #WebKitURIRequest
+ *
+ * Returns: the HTTP method of the #WebKitURIRequest or %NULL if @request is not
+ *    an HTTP request.
+ */
+const gchar* webkit_uri_request_get_http_method(WebKitURIRequest* request)
+{
+    g_return_val_if_fail(WEBKIT_IS_URI_REQUEST(request), 0);
+
+    if (!request->priv->resourceRequest.url().protocolIsInHTTPFamily())
+        return 0;
+
+    request->priv->http_method = request->priv->resourceRequest.httpMethod().utf8();
+    return request->priv->http_method.data();
+}
+
 WebKitURIRequest* webkitURIRequestCreateForResourceRequest(const ResourceRequest& resourceRequest)
 {
     WebKitURIRequest* uriRequest = WEBKIT_URI_REQUEST(g_object_new(WEBKIT_TYPE_URI_REQUEST, NULL));
diff -ur webkit-2.10.3.orig/Source/WebKit2/UIProcess/API/gtk/WebKitURIRequest.h webkit-2.10.3/Source/WebKit2/UIProcess/API/gtk/WebKitURIRequest.h
--- webkit-2.10.3.orig/Source/WebKit2/UIProcess/API/gtk/WebKitURIRequest.h	2015-10-30 14:17:22.000000000 +0100
+++ webkit-2.10.3/Source/WebKit2/UIProcess/API/gtk/WebKitURIRequest.h	2015-11-22 10:43:34.491738869 +0100
@@ -70,6 +70,9 @@
 webkit_uri_request_set_uri          (WebKitURIRequest *request,
                                      const gchar      *uri);
 
+WEBKIT_API const gchar *
+webkit_uri_request_get_http_method          (WebKitURIRequest *request);
+
 WEBKIT_API SoupMessageHeaders *
 webkit_uri_request_get_http_headers (WebKitURIRequest *request);
 


More information about the webkit-gtk mailing list