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

Carlos Garcia Campos cgarcia at igalia.com
Sun Nov 22 23:45:52 PST 2015


El dom, 22-11-2015 a las 18:01 +0100, Jon Forsberg escribió:
> 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.

Thank you very much for the patch. It looks quite good in general,
there are just a few details like adding since tags to the docs, and
the lack of unit tests. In WebKit patches need to be submitted to
bugzilla for being reviewing. So, please, file a bug report in
bugs.webkit.org (Product WebKit, component WebKitGtk) and attach your
patch there. Patches need to have a ChangeLog entry, and new API
patches like this also require a unit test. See

http://www.webkit.org/coding/contributing.html
http://trac.webkit.org/wiki/WebKitGTK/AddingNewWebKit2API

Some comments about the patch, so that you can submit an updated
version to bugzilla directly:

> 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;

http_method -> httpMethod;

>      GUniquePtr&lt;SoupMessageHeaders&gt; 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.
> + */

You should add here Since: 2.12

> +const gchar* webkit_uri_request_get_http_method(WebKitURIRequest* request)
> +{
> +    g_return_val_if_fail(WEBKIT_IS_URI_REQUEST(request), 0);

Use nullptr instead of 0.

> 
> +    if (!request->priv->resourceRequest.url().protocolIsInHTTPFamily())
> +        return 0;

Ditto.

> 
> +    request->priv->http_method = request->priv->resourceRequest.httpMethod().utf8();
> +    return request-&gt;priv-&gt;http_method.data();

I wonder if we could return g_intern_static_string() so that the caller
could compare the result with SOUP_METHOD_ directly.

> +}
> +
>  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);

> 
> 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=0xF3D322D0EC45
> > 82C3
> > 
> > 
> > _______________________________________________
> > webkit-gtk mailing list
> > webkit-gtk at lists.webkit.org
> > https://lists.webkit.org/mailman/listinfo/webkit-gtk
> > 
> _______________________________________________
> 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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: This is a digitally signed message part
URL: <https://lists.webkit.org/pipermail/webkit-gtk/attachments/20151123/1c50d357/attachment.sig>


More information about the webkit-gtk mailing list