add option -C to force closing of connections

This commit is contained in:
Christian Grothoff 2015-09-21 10:43:22 +02:00
parent 49d8426cf4
commit a9f01707ad
8 changed files with 75 additions and 0 deletions

View File

@ -13,6 +13,9 @@ taler\-mint\-httpd \- Run Taler mint (with RESTful API)
.SH OPTIONS
.B
.IP "\-C, \-\-connection-close"
Force each HTTP connection to be closed after each request (useful in combination with \-f to avoid having to wait for nc to time out).
.B
.IP "\-d DIRNAME, \-\-mint-dir=DIRNAME"
Use the configuration and other resources for the mint to operate from DIRNAME.
.B

View File

@ -44,6 +44,11 @@
*/
char *TMH_mint_currency_string;
/**
* Should we return "Connection: close" in each response?
*/
int TMH_mint_connection_close;
/**
* Base directory of the mint (global)
*/
@ -543,11 +548,13 @@ run_fake_client ()
"nc",
"localhost",
ports,
"-w", "30",
NULL)) &&
(0 != execlp ("ncat",
"ncat",
"localhost",
ports,
"-i", "30",
NULL)) )
{
fprintf (stderr,
@ -614,6 +621,9 @@ main (int argc,
char *const *argv)
{
static const struct GNUNET_GETOPT_CommandLineOption options[] = {
{'C', "connection-close", NULL,
"force HTTP connections to be closed after each request", 0,
&GNUNET_GETOPT_set_one, &TMH_mint_connection_close},
{'d', "mint-dir", "DIR",
"mint directory with configuration and keys for operating the mint", 1,
&GNUNET_GETOPT_set_filename, &TMH_mint_directory},

View File

@ -32,6 +32,11 @@
*/
extern char *TMH_mint_currency_string;
/**
* Should we return "Connection: close" in each response?
*/
extern int TMH_mint_connection_close;
/**
* The mint's configuration.
*/

View File

@ -23,6 +23,7 @@
#include "platform.h"
#include <pthread.h>
#include "taler-mint-httpd_keystate.h"
#include "taler-mint-httpd_responses.h"
#include "taler_mintdb_plugin.h"
@ -813,6 +814,17 @@ handle_sighup ()
}
/**
* Call #handle_signal() to pass the received signal via
* the control pipe.
*/
static void
handle_sigchld ()
{
handle_signal (SIGCHLD);
}
/**
* Read signals from a pipe in a loop, and reload keys from disk if
* SIGUSR1 is received, terminate if SIGTERM/SIGINT is received, and
@ -829,6 +841,7 @@ TMH_KS_loop (void)
struct GNUNET_SIGNAL_Context *sigterm;
struct GNUNET_SIGNAL_Context *sigint;
struct GNUNET_SIGNAL_Context *sighup;
struct GNUNET_SIGNAL_Context *sigchld;
int ret;
if (0 != pipe (reload_pipe))
@ -845,6 +858,8 @@ TMH_KS_loop (void)
&handle_sigint);
sighup = GNUNET_SIGNAL_handler_install (SIGHUP,
&handle_sighup);
sigchld = GNUNET_SIGNAL_handler_install (SIGCHLD,
&handle_sigchld);
ret = 0;
while (0 == ret)
@ -890,6 +905,12 @@ read_again:
/* restart updated binary */
ret = GNUNET_NO;
break;
#if HAVE_DEVELOPER
case SIGCHLD:
/* running in test-mode, test finished, terminate */
ret = GNUNET_OK;
break;
#endif
default:
/* unexpected character */
GNUNET_break (0);
@ -905,6 +926,7 @@ read_again:
GNUNET_SIGNAL_handler_uninstall (sigterm);
GNUNET_SIGNAL_handler_uninstall (sigint);
GNUNET_SIGNAL_handler_uninstall (sighup);
GNUNET_SIGNAL_handler_uninstall (sigchld);
return ret;
}
@ -966,6 +988,7 @@ TMH_KS_handler_keys (struct TMH_RequestHandler *rh,
GNUNET_break (0);
return MHD_NO;
}
TMH_RESPONSE_add_global_headers (response);
(void) MHD_add_response_header (response,
"Content-Type",
rh->mime_type);

View File

@ -65,6 +65,7 @@ TMH_MHD_handler_static_response (struct TMH_RequestHandler *rh,
GNUNET_break (0);
return MHD_NO;
}
TMH_RESPONSE_add_global_headers (response);
if (NULL != rh->mime_type)
(void) MHD_add_response_header (response,
MHD_HTTP_HEADER_CONTENT_TYPE,
@ -108,6 +109,7 @@ TMH_MHD_handler_agpl_redirect (struct TMH_RequestHandler *rh,
GNUNET_break (0);
return MHD_NO;
}
TMH_RESPONSE_add_global_headers (response);
if (NULL != rh->mime_type)
(void) MHD_add_response_header (response,
MHD_HTTP_HEADER_CONTENT_TYPE,

View File

@ -29,6 +29,23 @@
#include "taler-mint-httpd_keystate.h"
/**
* Add headers we want to return in every response.
* Useful for testing, like if we want to always close
* connections.
*
* @param response response to modify
*/
void
TMH_RESPONSE_add_global_headers (struct MHD_Response *response)
{
if (TMH_mint_connection_close)
(void) MHD_add_response_header (response,
MHD_HTTP_HEADER_CONNECTION,
"close");
}
/**
* Send JSON object as response.
*
@ -56,6 +73,7 @@ TMH_RESPONSE_reply_json (struct MHD_Connection *connection,
GNUNET_break (0);
return MHD_NO;
}
TMH_RESPONSE_add_global_headers (resp);
(void) MHD_add_response_header (resp,
MHD_HTTP_HEADER_CONTENT_TYPE,
"application/json");
@ -292,6 +310,7 @@ TMH_RESPONSE_reply_request_too_large (struct MHD_Connection *connection)
MHD_RESPMEM_PERSISTENT);
if (NULL == resp)
return MHD_NO;
TMH_RESPONSE_add_global_headers (resp);
ret = MHD_queue_response (connection,
MHD_HTTP_REQUEST_ENTITY_TOO_LARGE,
resp);

View File

@ -32,6 +32,16 @@
#include "taler-mint-httpd.h"
#include "taler-mint-httpd_db.h"
/**
* Add headers we want to return in every response.
* Useful for testing, like if we want to always close
* connections.
*
* @param response response to modify
*/
void
TMH_RESPONSE_add_global_headers (struct MHD_Response *response);
/**
* Send JSON object as response.

View File

@ -106,6 +106,7 @@ TMH_WIRE_handler_wire_test (struct TMH_RequestHandler *rh,
GNUNET_break (0);
return MHD_NO;
}
TMH_RESPONSE_add_global_headers (response);
for (i=0;NULL != TMH_expected_wire_formats[i];i++)
if (0 == strcasecmp ("test",
TMH_expected_wire_formats[i]))
@ -179,6 +180,7 @@ TMH_WIRE_handler_wire_sepa (struct TMH_RequestHandler *rh,
GNUNET_break (0);
return MHD_NO;
}
TMH_RESPONSE_add_global_headers (response);
ret = MHD_queue_response (connection,
MHD_HTTP_NOT_IMPLEMENTED,
response);
@ -225,6 +227,7 @@ TMH_WIRE_handler_wire_sepa (struct TMH_RequestHandler *rh,
GNUNET_break (0);
return MHD_NO;
}
TMH_RESPONSE_add_global_headers (response);
if (NULL != rh->mime_type)
(void) MHD_add_response_header (response,
MHD_HTTP_HEADER_CONTENT_TYPE,