diff --git a/src/include/d_options.rec b/src/include/d_options.rec index 1ad10874..073aef01 100644 --- a/src/include/d_options.rec +++ b/src/include/d_options.rec @@ -385,6 +385,24 @@ Comment: Disable #MHD_action_suspend() functionality. + You should only use this function if you do not use suspend functionality and need a generally minor boost in performance. + The suspend is not disallowed (suspend is allowed) by default. +Name: DISABLE_COOKIES +Value: 324 +Type: enum MHD_Bool +Comment: Disable cookies parsing. ++ ++ Disable automatic cookies processing if cookies are not used. ++ Cookies are automatically parsed by default. +CustomSetter: /* custom setter */ ++ /* The is not an easy for automatic generations */ ++ // TODO: remove options generator, put preprocessor directives to ++ // the first column ++ #ifdef MHD_SUPPORT_COOKIES ++ settings->disable_cookies = option->val.disable_cookies; ++ #else ++ if (MHD_NO != option->val.disable_cookies) ++ return MHD_SC_FEATURE_DISABLED; ++ #endif + # Notification callbacks Name: daemon_ready_callback diff --git a/src/include/microhttpd2.h b/src/include/microhttpd2.h index 888c4466..00ef5243 100644 --- a/src/include/microhttpd2.h +++ b/src/include/microhttpd2.h @@ -4399,6 +4399,18 @@ MHD_D_OPTION_DISALLOW_SUSPEND_RESUME ( enum MHD_Bool value ); +/** + * Disable cookies parsing. + * +Disable automatic cookies processing if cookies are not used. + * Cookies are automatically parsed by default. + * @param value the value of the parameter * @return structure with the requested setting + */ +struct MHD_DaemonOptionAndValue +MHD_D_OPTION_DISABLE_COOKIES ( + enum MHD_Bool value + ); + /** * Set a callback to be called for pre-start finalisation. * diff --git a/src/include/microhttpd2_generated_daemon_options.h b/src/include/microhttpd2_generated_daemon_options.h index 881c5898..8431d8c0 100644 --- a/src/include/microhttpd2_generated_daemon_options.h +++ b/src/include/microhttpd2_generated_daemon_options.h @@ -274,6 +274,15 @@ You should only use this function if you do not use suspend functionality and ne MHD_D_O_DISALLOW_SUSPEND_RESUME = 323 , + /** + * Disable cookies parsing. + * +Disable automatic cookies processing if cookies are not used. + * Cookies are automatically parsed by default. + */ + MHD_D_O_DISABLE_COOKIES = 324 + , + /** * Set a callback to be called for pre-start finalisation. * @@ -766,6 +775,11 @@ union MHD_DaemonOptionValue */ enum MHD_Bool disallow_suspend_resume; + /** + * Value for #MHD_D_O_DISABLE_COOKIES. + */ + enum MHD_Bool disable_cookies; + /** * Value for #MHD_D_O_DAEMON_READY_CALLBACK. * the pre-start callback @@ -1331,6 +1345,21 @@ You should only use this function if you do not use suspend functionality and ne .val.disallow_suspend_resume = (value) \ } \ MHD_RESTORE_WARN_COMPOUND_LITERALS_ +/** + * Disable cookies parsing. + * +Disable automatic cookies processing if cookies are not used. + * Cookies are automatically parsed by default. + * @param value the value of the parameter * @return structure with the requested setting + */ +# define MHD_D_OPTION_DISABLE_COOKIES(value) \ + MHD_NOWARN_COMPOUND_LITERALS_ \ + (const struct MHD_DaemonOptionAndValue) \ + { \ + .opt = MHD_D_O_DISABLE_COOKIES, \ + .val.disable_cookies = (value) \ + } \ + MHD_RESTORE_WARN_COMPOUND_LITERALS_ /** * Set a callback to be called for pre-start finalisation. * @@ -2167,6 +2196,27 @@ MHD_D_OPTION_DISALLOW_SUSPEND_RESUME ( } +/** + * Disable cookies parsing. + * +Disable automatic cookies processing if cookies are not used. + * Cookies are automatically parsed by default. + * @param value the value of the parameter * @return structure with the requested setting + */ +static MHD_INLINE struct MHD_DaemonOptionAndValue +MHD_D_OPTION_DISABLE_COOKIES ( + enum MHD_Bool value + ) +{ + struct MHD_DaemonOptionAndValue opt_val; + + opt_val.opt = MHD_D_O_DISABLE_COOKIES; + opt_val.val.disable_cookies = (value); \ + + return opt_val; +} + + /** * Set a callback to be called for pre-start finalisation. * diff --git a/src/mhd2/daemon_options.h b/src/mhd2/daemon_options.h index 8cc0bd2d..e6b86abd 100644 --- a/src/mhd2/daemon_options.h +++ b/src/mhd2/daemon_options.h @@ -231,6 +231,12 @@ struct DaemonOptions enum MHD_Bool disallow_suspend_resume; + /** + * Value for #MHD_D_O_DISABLE_COOKIES. + */ + enum MHD_Bool disable_cookies; + + /** * Value for #MHD_D_O_DAEMON_READY_CALLBACK. * the pre-start callback diff --git a/src/mhd2/daemon_set_options.c b/src/mhd2/daemon_set_options.c index d67099b5..1cd10aec 100644 --- a/src/mhd2/daemon_set_options.c +++ b/src/mhd2/daemon_set_options.c @@ -198,6 +198,18 @@ MHD_daemon_set_options ( case MHD_D_O_DISALLOW_SUSPEND_RESUME: settings->disallow_suspend_resume = option->val.disallow_suspend_resume; continue; + case MHD_D_O_DISABLE_COOKIES: + /* custom setter */ + /* The is not an easy for automatic generations */ + // TODO: remove options generator, put preprocessor directives to + // the first column + #ifdef MHD_SUPPORT_COOKIES + settings->disable_cookies = option->val.disable_cookies; + #else + if (MHD_NO != option->val.disable_cookies) + return MHD_SC_FEATURE_DISABLED; + #endif + continue; case MHD_D_O_DAEMON_READY_CALLBACK: settings->daemon_ready_callback.v_cb = option->val.daemon_ready_callback.v_cb; settings->daemon_ready_callback.v_cb_cls = option->val.daemon_ready_callback.v_cb_cls; diff --git a/src/mhd2/daemon_start.c b/src/mhd2/daemon_start.c index 38e63065..d2d4db8c 100644 --- a/src/mhd2/daemon_start.c +++ b/src/mhd2/daemon_start.c @@ -129,6 +129,10 @@ daemon_set_basic_settings (struct MHD_Daemon *restrict d, { d->req_cfg.strictness = s->protocol_strict_level.v_sl; +#ifdef MHD_SUPPORT_COOKIES + d->req_cfg.disable_cookies = (MHD_NO != s->disable_cookies); +#endif + d->req_cfg.suppress_date = (MHD_NO != s->suppress_date_header); return MHD_SC_OK; diff --git a/src/mhd2/mhd_daemon.h b/src/mhd2/mhd_daemon.h index 4512a996..d49a1350 100644 --- a/src/mhd2/mhd_daemon.h +++ b/src/mhd2/mhd_daemon.h @@ -940,6 +940,13 @@ struct mhd_DaemonRequestProcessingSettings */ enum MHD_ProtocolStrictLevel strictness; +#ifdef MHD_SUPPORT_COOKIES + /** + * Disable automatic cookies parsing + */ + bool disable_cookies; +#endif + /** * Early URI callback */ diff --git a/src/mhd2/stream_process_request.c b/src/mhd2/stream_process_request.c index 9c686840..fe6a2230 100644 --- a/src/mhd2/stream_process_request.c +++ b/src/mhd2/stream_process_request.c @@ -2745,7 +2745,8 @@ mhd_stream_parse_request_headers (struct MHD_Connection *restrict c) #ifdef MHD_SUPPORT_COOKIES /* "Cookie:" */ - if (mhd_str_equal_caseless_n_st (MHD_HTTP_HEADER_COOKIE, + if ((! c->daemon->req_cfg.disable_cookies) && + mhd_str_equal_caseless_n_st (MHD_HTTP_HEADER_COOKIE, f->field.nv.name.cstr, f->field.nv.name.len)) {