After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 625645 - Inconsistent server-side API for async handling HTTP GET and POST
Inconsistent server-side API for async handling HTTP GET and POST
Status: RESOLVED FIXED
Product: libsoup
Classification: Core
Component: API
2.31.x
Other All
: Normal normal
: ---
Assigned To: libsoup-maint@gnome.bugs
libsoup-maint@gnome.bugs
Depends on:
Blocks:
 
 
Reported: 2010-07-30 10:42 UTC by Zeeshan Ali
Modified: 2015-03-01 15:41 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Zeeshan Ali 2010-07-30 10:42:32 UTC
Currently the advertised (in the docs) way of handling messages on the server side is to hook-up a handler method to SoupServer using soup_server_add_handler(). This works for both HTTP GET and POST (and perhaps other HTTP methods too). However, if you want to handle messages asynchronously and send response piece-by-piece, you can not handle 'POST' using the server handler.

Here is the example code in rygel: http://git.gnome.org/browse/rygel/tree/src/rygel/rygel-http-server.vala#n52
Comment 1 Dan Winship 2010-08-16 02:10:37 UTC
OK, I figured out an easy fix for this. However, as part of my continuing attempt to get more people submitting patches to libsoup, I will merely describe it rather than actually implementing it. :)

Basically, just add a new property to SoupServer, called something like "dispatch-before-body". If TRUE, the handlers would be invoked from the got-headers callback rather than the got-body callback. Then you could connect to got-chunk, etc, from the handler if there was going to be a body, rather than having to deal with request-started, etc. Or if you needed to look at the request body but didn't want to stream it, you could just connect to "got-body" and postpone processing until then.

It should be pretty trivial to implement, though of course you'll want to test that it actually works the way you want in rygel too...
Comment 2 Zeeshan Ali 2010-08-17 20:41:40 UTC
Thanks, I'll look into it. However we are entering API freeze soon for GNOME 2.32 and I don't think I can get around to doing this before that. :(
Comment 3 Dan Winship 2010-08-17 21:56:32 UTC
libsoup is Desktop, not Platform, so it's not bound by API freeze
Comment 4 Nirbheek Chauhan 2014-09-13 14:00:49 UTC
(In reply to comment #1)
> Basically, just add a new property to SoupServer, called something like
> "dispatch-before-body". If TRUE, the handlers would be invoked from the
> got-headers callback rather than the got-body callback. 

Wouldn't it be better to have this on a per-handler basis? A sufficiently complex application would need to handle chunked requests/responses as well as ordinary one-off requests/responses. I've been working on such an application, and a server-wide flag would just trade reduced complexity for chunked/async handlers with increased complexity for ordinary handlers.

Perhaps something like soup_server_add_header_handler () that would register a callback to be invoked in got-headers instead of got-body.
Comment 5 Dan Winship 2014-09-15 13:05:40 UTC
(In reply to comment #4)
> Wouldn't it be better to have this on a per-handler basis?

Yes, probably

> Perhaps something like soup_server_add_header_handler () that would register a
> callback to be invoked in got-headers instead of got-body.

At some point I wanted to add a GIOStream-based handler API as well, so that you could read the request body and write the response body via GInputStream/GOutputStream, like with the newer SoupSession APIs...
Comment 6 Nirbheek Chauhan 2014-09-16 23:06:02 UTC
(In reply to comment #5)
> (In reply to comment #4)
> > Perhaps something like soup_server_add_header_handler () that would register a
> > callback to be invoked in got-headers instead of got-body.
> 
> At some point I wanted to add a GIOStream-based handler API as well, so that
> you could read the request body and write the response body via
> GInputStream/GOutputStream, like with the newer SoupSession APIs...

I'd be interested in working on both handling of callbacks when headers are received and on adding a GIOStream-based API (bug 719642?). I'd like to start with the former, and would appreciate some advice on what the API should look like for it, thanks!
Comment 7 Dan Winship 2014-09-17 13:50:42 UTC
I started working on this at one point; I've pushed the work-in-progress to wip/server-early.
Comment 8 Nirbheek Chauhan 2014-09-17 20:45:42 UTC
(In reply to comment #7)
> I started working on this at one point; I've pushed the work-in-progress to
> wip/server-early.

I read through everything, and it actually looks complete to me. :)

What's left to do, besides testing it and writing tests?
Comment 9 Dan Winship 2014-09-17 21:05:38 UTC
It's possible that it's basically complete. I don't remember what state it was in when I last touched it.
Comment 10 Dan Winship 2015-02-10 11:57:55 UTC
[mass-moving all "UNCONFIRMED" libsoup bugs to "NEW" after disabling the "UNCONFIRMED" status for this product now that bugzilla.gnome.org allows that. bugspam-libsoup-20150210]
Comment 11 Dan Winship 2015-03-01 15:41:15 UTC
soup_server_add_early_handler() now exists in master