c - Calling functions from mongoose begin_request_handler callback -


currently i'm working on application embeds mongoose webserver. in cases, have call additional functions inside begin_request_handler create desired http header. during this, realized theses functions called after request handler done. example:

void test() {     printf("hello"); }     static int begin_request_handler(struct mg_connection *conn) {     test();     const struct mg_request_info *request_info = mg_get_request_info(conn);     ...     return 1; } 

here hello getting printed right after browser closes tcp connection. there way call functions inside callbacks? or missing something?

  1. if want create desired http header. function mentioned above (begin_request_handler) may not correct approach. structure mg_request_info field in structure mg_connection. here name , value of headers set. think these structures populated @ start after connection establishment. @ pull() , read(). these ground-level function data set.

  2. and yes there way call functions callbacks.you can write own callback , make callback function point in struct of mg_context make point callback. , in handle_request() can call appropriately. can add struct mg_callbacks in mongoose.h

example:

memset(&callbacks, 0, sizeof(callbacks));
callbacks.begin_request => begin_request_handler;

//place function in place of begin_request_handler
// start web server.

ctx = mg_start(&callbacks, null, options);

please specify more details maybe interested in.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -