2727#include < unistd.h>
2828#include < sys/stat.h>
2929#include < sys/types.h>
30+ #include < signal.h>
3031#ifdef WITH_PYTHON
3132#include < Python.h>
3233#endif
@@ -40,6 +41,26 @@ void access_log(Webserver*, string);
4041size_t unescaper_func (void *, struct MHD_Connection *, char *);
4142size_t internal_unescaper (void *, struct MHD_Connection *, char *);
4243
44+ static void catcher (int sig)
45+ {
46+ }
47+
48+ static void ignore_sigpipe ()
49+ {
50+ struct sigaction oldsig;
51+ struct sigaction sig;
52+
53+ sig.sa_handler = &catcher;
54+ sigemptyset (&sig.sa_mask );
55+ #ifdef SA_INTERRUPT
56+ sig.sa_flags = SA_INTERRUPT ; /* SunOS */
57+ #else
58+ sig.sa_flags = SA_RESTART ;
59+ #endif
60+ if (0 != sigaction (SIGPIPE , &sig, &oldsig))
61+ fprintf (stderr, " Failed to install SIGPIPE handler: %s\n " , strerror (errno));
62+ }
63+
4364// ENDPOINT
4465HttpEndpoint::HttpEndpoint (bool family):
4566 url_complete(" /" ),
@@ -753,15 +774,6 @@ const std::vector<std::pair<std::string, std::string> > HttpResponse::getHeaders
753774 return toRet;
754775}
755776
756- const std::vector<std::pair<std::string, std::string> > HttpResponse::getCookies ()
757- {
758- std::vector<std::pair<std::string, std::string> > toRet;
759- map<string, string, HeaderComparator>::const_iterator it;
760- for (it = cookies.begin (); it != cookies.end (); it++)
761- toRet.push_back (make_pair<string, string>((*it).first ,(*it).second ));
762- return toRet;
763- }
764-
765777const std::vector<std::pair<std::string, std::string> > HttpResponse::getFooters ()
766778{
767779 std::vector<std::pair<std::string, std::string> > toRet;
@@ -785,13 +797,6 @@ void HttpResponse::setFooters(const map<string, string>& footers)
785797 this ->footers [it->first ] = it->second ;
786798}
787799
788- void HttpResponse::setCookies (const map<string, string>& cookies)
789- {
790- map<string, string>::const_iterator it;
791- for (it = cookies.begin (); it != cookies.end (); it ++)
792- this ->cookies [it->first ] = it->second ;
793- }
794-
795800int HttpResponse::getResponseCode ()
796801{
797802 return this ->responseCode ;
@@ -829,6 +834,7 @@ void Unescaper::unescape(char* s) const {}
829834Webserver::Webserver
830835(
831836 const int port,
837+ const HttpUtils::StartMethod_T startMethod,
832838 const int maxThreads,
833839 const int maxConnections,
834840 const int memoryLimit,
@@ -838,6 +844,10 @@ Webserver::Webserver
838844 const RequestValidator* validator,
839845 const Unescaper* unescaper,
840846 const int maxThreadStackSize,
847+ const bool useSsl,
848+ const bool useIpv6,
849+ const bool debug,
850+ const bool pedantic,
841851 const string& httpsMemKey,
842852 const string& httpsMemCert,
843853 const string& httpsMemTrust,
@@ -855,6 +865,11 @@ Webserver::Webserver
855865 logDelegate(logDelegate),
856866 validator(validator),
857867 unescaper(unescaper),
868+ maxThreadStackSize(maxThreadStackSize),
869+ useSsl(useSsl),
870+ useIpv6(useIpv6),
871+ debug(debug),
872+ pedantic(pedantic),
858873 httpsMemKey(httpsMemKey),
859874 httpsMemCert(httpsMemCert),
860875 httpsMemTrust(httpsMemTrust),
@@ -864,6 +879,7 @@ Webserver::Webserver
864879 nonceNcSize(nonceNcSize),
865880 running(false )
866881{
882+ ignore_sigpipe ();
867883}
868884
869885Webserver::~Webserver ()
@@ -903,11 +919,9 @@ bool Webserver::start(bool blocking)
903919 vector<struct MHD_OptionItem > iov;
904920
905921 iov.push_back (gen (MHD_OPTION_NOTIFY_COMPLETED , (intptr_t ) &requestCompleted, NULL ));
906- iov.push_back (gen (MHD_OPTION_URI_LOG_CALLBACK , (intptr_t )&uri_log, this ));
907- iov.push_back (gen (MHD_OPTION_EXTERNAL_LOGGER , (intptr_t )&error_log, this ));
908- iov.push_back (gen (MHD_OPTION_UNESCAPE_CALLBACK , (intptr_t )&unescaper_func, this ));
909- if (connectionTimeout == 0 )
910- connectionTimeout = DEFAULT_DROP_WS_TIMEOUT ;
922+ iov.push_back (gen (MHD_OPTION_URI_LOG_CALLBACK , (intptr_t ) &uri_log, this ));
923+ iov.push_back (gen (MHD_OPTION_EXTERNAL_LOGGER , (intptr_t ) &error_log, this ));
924+ iov.push_back (gen (MHD_OPTION_UNESCAPE_CALLBACK , (intptr_t ) &unescaper_func, this ));
911925 iov.push_back (gen (MHD_OPTION_CONNECTION_TIMEOUT , connectionTimeout));
912926 if (maxThreads != 0 )
913927 iov.push_back (gen (MHD_OPTION_THREAD_POOL_SIZE , maxThreads));
@@ -942,9 +956,19 @@ bool Webserver::start(bool blocking)
942956 ops[i] = iov[i];
943957 }
944958
959+ int startConf = startMethod;
960+ if (useSsl)
961+ startConf |= MHD_USE_SSL ;
962+ if (useIpv6)
963+ startConf |= MHD_USE_IPv6;
964+ if (debug)
965+ startConf |= MHD_USE_DEBUG ;
966+ if (pedantic)
967+ startConf |= MHD_USE_PEDANTIC_CHECKS ;
968+
945969 this ->daemon = MHD_start_daemon
946970 (
947- MHD_USE_SELECT_INTERNALLY , this ->port , &policyCallback, this ,
971+ startConf , this ->port , &policyCallback, this ,
948972 &answerToConnection, this , MHD_OPTION_ARRAY , ops, MHD_OPTION_END
949973 );
950974
0 commit comments