GNOME Bugzilla – Bug 625645
Inconsistent server-side API for async handling HTTP GET and POST
Last modified: 2015-03-01 15:41:15 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
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...
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. :(
libsoup is Desktop, not Platform, so it's not bound by API freeze
(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.
(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...
(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!
I started working on this at one point; I've pushed the work-in-progress to wip/server-early.
(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?
It's possible that it's basically complete. I don't remember what state it was in when I last touched it.
[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]
soup_server_add_early_handler() now exists in master