You are absolutely right! :-) I did the same test using the MHD POST demo and it worked like a charm. But I need to read about "100 continue", because I don't know it yet.
Thank you very much and happy hacking! :-D On Thu, Nov 5, 2015 at 8:51 PM, Christian Grothoff <[email protected]> wrote: > Hi! > > Your server is to simplistic. > > You're not handling the "100 continue" acceptably in the C code. > Essentially, by queuing a reply on the first callback, you tell MHD to > abort handling the POST (after all, your implementation also below never > processes the uploaded data, and it had no chance to do so). And > because the POST is being *refused* (from MHD's perspective, even though > you return 200 OK), MHD gives you a "Connection: close" for free on top > (as otherwise we might be confused with the client's upload data that > we're now just dropping). > > Try handling the POST data "for real" (RTFM, and/or look at actual > examples!), and then you'll get your keep-alive from MHD as well. > > Happy hacking! > > Christian > > > On 11/05/2015 11:43 PM, silvioprog wrote: > > Hello, > > > > Is the keep-alive feature compatible only with GET method? See this log > > below, it compares the headers from MHD and NodeJS: > > > > === NodeJS === > > > > ... GET ... > > > > $ curl -I http://127.0.0.1:8080 > > HTTP/1.1 200 OK > > Content-Type: text/html > > Date: Thu, 05 Nov 2015 22:34:34 GMT > > *Connection: keep-alive* > > > > ... POST ... > > > > $ curl -X POST -I http://127.0.0.1:8080 > > HTTP/1.1 200 OK > > Content-Type: text/html > > Date: Thu, 05 Nov 2015 22:36:45 GMT > > *Connection: keep-alive* > > Transfer-Encoding: chunked > > > > === NodeJS === > > > > === MHD === > > > > ... GET ... > > > > $ curl -I http://127.0.0.1:8080 > > HTTP/1.1 200 OK > > Content-Length: 76 > > Content-Type: text/html > > *Connection: keep-alive* > > Date: Thu, 05 Nov 2015 22:39:37 GMT > > > > ... POST ... > > > > $ curl -X POST -I http://127.0.0.1:8080 > > HTTP/1.1 200 OK > > *Connection: close* > > Content-Length: 76 > > Content-Type: text/html > > Date: Thu, 05 Nov 2015 22:41:20 GMT > > > > === MHD === > > > > Source codes: > > > > helloworld_nodejs.js: > > ------- > > const PORT = 8080; > > var http = require('http'); > > var body = '<html><head><title>Hello world</title></head><body>Hello > > world</body></html>'; > > http.createServer(function (req, res) { > > res.writeHead(200, {'Content-Type': 'text/html'}); > > res.end(body); > > }).listen(PORT); > > console.log('Server is running on port ' + PORT); > > ------- > > > > helloworld_mhd.c: > > ------- > > #include <microhttpd.h> > > #include <string.h> > > #include <stdio.h> > > > > #define PORT 8080 > > #define PAGE "<html><head><title>Hello world</title></head><body>Hello > > world</body></html>" > > > > static struct MHD_Response *response; > > > > static int ahc_echo(void *cls, struct MHD_Connection *connection, const > > char *url, const char *method, > > const char *version, const char *upload_data, size_t > > *upload_data_size, void **ptr) { > > return MHD_queue_response(connection, MHD_HTTP_OK, response); > > } > > > > int main(int argc, char *const *argv) { > > struct MHD_Daemon *d; > > response = MHD_create_response_from_buffer(strlen(PAGE), (void *) > PAGE, > > MHD_RESPMEM_PERSISTENT); > > (void) MHD_add_response_header(response, MHD_HTTP_HEADER_CONNECTION, > > "keep-alive"); > > (void) MHD_add_response_header(response, > MHD_HTTP_HEADER_CONTENT_TYPE, > > "text/html"); > > d = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY, > > PORT, NULL, NULL, &ahc_echo, NULL, > > MHD_OPTION_END); > > if (d == NULL) > > return 1; > > printf("Server is running on port %d", PORT); > > getchar(); > > MHD_stop_daemon(d); > > MHD_destroy_response(response); > > return 0; > > } > > ------- > > > > Thank you! > -- Silvio Clécio
