Re: libsoup server



Dan Winship wrote:
Dennis Jacobfeuerborn wrote:
Hi!
I'm trying to build a small server using libsoup but seem to get into trouble early on. The following app seems to listen on port 8888 just fine but when I send a request with Firefox sits there saying "Waiting for localhost..." and nothing happens:

int main( int argc, char *argv[] ) {
     g_type_init();
     g_thread_init(NULL);
     SoupServer *soup_server = soup_server_new(SOUP_SERVER_PORT , 8888, NULL);
     soup_server_run(soup_server);
     return 0;
}

Using strace on this app results in the following output:

fcntl64(6, F_GETFL)                     = 0x802 (flags O_RDWR|O_NONBLOCK)
read(6, "GET / HTTP/1.1\r\nHost: localhost:"..., 8192) = 396
rt_sigaction(SIGPIPE, {SIG_IGN}, {SIG_DFL}, 8) = 0
write(6, "HTTP/1.1 404 Not Found\r\n\r\n", 26) = 26
rt_sigaction(SIGPIPE, {SIG_DFL}, {SIG_IGN}, 8) = 0
read(6, 0x83717a0, 8192) = -1 EAGAIN (Resource temporarily unavailable)

So it seems libsoup is sending out the expected 404 error (since no handler is defined) but for some reason the response doesn't arrive at the other end. Can somebody tell me what I am doing wrong here?

You're not doing anything wrong. It looks like SoupServer's built-in 404
handler is broken; it needs to either include "Content-Length: 0" in the
response, or close the connection after it.

So you'll have to register a default handler (a handler with path ==
NULL) and have it return a correct 404 error for any URL that you don't
handle.

2.2.95 has already gone out, so this won't be fixed in libsoup until 2.2.96.

Thanks for the response. I finally found some time to look into this again but things still don't seem to work. I implemented a minimal handler like this:

static void server_callback (SoupServerContext *context, SoupMessage *msg,
                             gpointer data) {
    g_printf("callback\n");
    soup_message_set_status (msg, SOUP_STATUS_NOT_FOUND);
    return;
}

and I right before the soup_server_run() I setup the callback like this:

soup_server_add_handler (soup_server, "/foo", NULL, server_callback,
                         NULL, NULL);

When I now call a URL starting with "/foo/..." the handler get called (I can see the "callback" output in the shell) but the browser still gets "stuck" just like the broken default handler. I took the handler code from the example in the "Soup Server Basics" documentation so I hoped this would work even if it doesn't do anything useful yet :)
Do you have any idea what might be wrong?

Regards,
  Dennis



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]