@@ -2039,18 +2039,19 @@ typedef int (*nghttp2_on_header_callback2)(nghttp2_session *session, |
2039 | 2039 | /** |
2040 | 2040 | * @functypedef |
2041 | 2041 | * |
2042 | | - * Callback function invoked when a invalid header name/value pair is |
| 2042 | + * Callback function invoked when an invalid header name/value pair is |
2043 | 2043 | * received for the |frame|. |
2044 | 2044 | * |
2045 | 2045 | * The parameter and behaviour are similar to |
2046 | 2046 | * :type:`nghttp2_on_header_callback`. The difference is that this |
2047 | | - * callback is only invoked when a invalid header name/value pair is |
2048 | | - * received which is treated as stream error if this callback is not |
2049 | | - * set. Only invalid regular header field are passed to this |
2050 | | - * callback. In other words, invalid pseudo header field is not |
2051 | | - * passed to this callback. Also header fields which includes upper |
2052 | | - * cased latter are also treated as error without passing them to this |
2053 | | - * callback. |
| 2047 | + * callback is only invoked when an invalid header name/value pair is |
| 2048 | + * received which is treated as stream error if this callback returns |
| 2049 | + * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` and |
| 2050 | + * :type:`nghttp2_on_invalid_header_callback2` is not set. Only |
| 2051 | + * invalid regular header field are passed to this callback. In other |
| 2052 | + * words, invalid pseudo header field is not passed to this callback. |
| 2053 | + * Also header fields which includes upper cased latter are also |
| 2054 | + * treated as error without passing them to this callback. |
2054 | 2055 | * |
2055 | 2056 | * This callback is only considered if HTTP messaging validation is |
2056 | 2057 | * turned on (which is on by default, see |
@@ -2076,17 +2077,18 @@ typedef int (*nghttp2_on_invalid_header_callback)( |
2076 | 2077 | /** |
2077 | 2078 | * @functypedef |
2078 | 2079 | * |
2079 | | - * Callback function invoked when a invalid header name/value pair is |
| 2080 | + * Callback function invoked when an invalid header name/value pair is |
2080 | 2081 | * received for the |frame|. |
2081 | 2082 | * |
2082 | 2083 | * The parameter and behaviour are similar to |
2083 | 2084 | * :type:`nghttp2_on_header_callback2`. The difference is that this |
2084 | | - * callback is only invoked when a invalid header name/value pair is |
2085 | | - * received which is silently ignored if this callback is not set. |
2086 | | - * Only invalid regular header field are passed to this callback. In |
2087 | | - * other words, invalid pseudo header field is not passed to this |
2088 | | - * callback. Also header fields which includes upper cased latter are |
2089 | | - * also treated as error without passing them to this callback. |
| 2085 | + * callback is only invoked when an invalid header name/value pair is |
| 2086 | + * received which is silently ignored if neither this callback nor |
| 2087 | + * :type:`nghttp2_on_invalid_header_callback` is set. Only invalid |
| 2088 | + * regular header field are passed to this callback. In other words, |
| 2089 | + * invalid pseudo header field is not passed to this callback. Also |
| 2090 | + * header fields which includes upper cased latter are also treated as |
| 2091 | + * error without passing them to this callback. |
2090 | 2092 | * |
2091 | 2093 | * This callback is only considered if HTTP messaging validation is |
2092 | 2094 | * turned on (which is on by default, see |
@@ -2445,6 +2447,15 @@ typedef int (*nghttp2_error_callback2)(nghttp2_session *session, |
2445 | 2447 | int lib_error_code, const char *msg, |
2446 | 2448 | size_t len, void *user_data); |
2447 | 2449 |
|
| 2450 | +/** |
| 2451 | + * @functypedef |
| 2452 | + * |
| 2453 | + * Callback function invoked when unpredictable data of |destlen| |
| 2454 | + * bytes are needed. The implementation must write unpredictable data |
| 2455 | + * of |destlen| bytes into the buffer pointed by |dest|. |
| 2456 | + */ |
| 2457 | +typedef void (*nghttp2_rand_callback)(uint8_t *dest, size_t destlen); |
| 2458 | + |
2448 | 2459 | struct nghttp2_session_callbacks; |
2449 | 2460 |
|
2450 | 2461 | /** |
@@ -2649,7 +2660,7 @@ NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_header_callback2( |
2649 | 2660 | /** |
2650 | 2661 | * @function |
2651 | 2662 | * |
2652 | | - * Sets callback function invoked when a invalid header name/value |
| 2663 | + * Sets callback function invoked when an invalid header name/value |
2653 | 2664 | * pair is received. If both |
2654 | 2665 | * `nghttp2_session_callbacks_set_on_invalid_header_callback()` and |
2655 | 2666 | * `nghttp2_session_callbacks_set_on_invalid_header_callback2()` are |
@@ -2662,7 +2673,7 @@ NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_invalid_header_callback( |
2662 | 2673 | /** |
2663 | 2674 | * @function |
2664 | 2675 | * |
2665 | | - * Sets callback function invoked when a invalid header name/value |
| 2676 | + * Sets callback function invoked when an invalid header name/value |
2666 | 2677 | * pair is received. |
2667 | 2678 | */ |
2668 | 2679 | NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_invalid_header_callback2( |
@@ -2833,6 +2844,18 @@ NGHTTP2_EXTERN void nghttp2_session_callbacks_set_error_callback( |
2833 | 2844 | NGHTTP2_EXTERN void nghttp2_session_callbacks_set_error_callback2( |
2834 | 2845 | nghttp2_session_callbacks *cbs, nghttp2_error_callback2 error_callback2); |
2835 | 2846 |
|
| 2847 | +/** |
| 2848 | + * @function |
| 2849 | + * |
| 2850 | + * Sets callback function invoked when unpredictable data is needed. |
| 2851 | + * Although this callback is optional due to the backward |
| 2852 | + * compatibility, it is recommended to specify it to harden the |
| 2853 | + * runtime behavior against suspicious activities of a remote |
| 2854 | + * endpoint. |
| 2855 | + */ |
| 2856 | +NGHTTP2_EXTERN void nghttp2_session_callbacks_set_rand_callback( |
| 2857 | + nghttp2_session_callbacks *cbs, nghttp2_rand_callback rand_callback); |
| 2858 | + |
2836 | 2859 | /** |
2837 | 2860 | * @functypedef |
2838 | 2861 | * |
@@ -3218,6 +3241,23 @@ nghttp2_option_set_stream_reset_rate_limit(nghttp2_option *option, |
3218 | 3241 | NGHTTP2_EXTERN void nghttp2_option_set_max_continuations(nghttp2_option *option, |
3219 | 3242 | size_t val); |
3220 | 3243 |
|
| 3244 | +/** |
| 3245 | + * @function |
| 3246 | + * |
| 3247 | + * This function sets the rate limit for the "glitches", the |
| 3248 | + * suspicious activities from a remote endpoint. It is a token-bucket |
| 3249 | + * based rate limiter. |burst| specifies the number of tokens that is |
| 3250 | + * initially available. The maximum number of tokens is capped to |
| 3251 | + * this value. |rate| specifies the number of tokens that are |
| 3252 | + * regenerated per second. When a suspicious activity is detected, |
| 3253 | + * some amount of tokens are consumed. If there is no token |
| 3254 | + * available, GOAWAY is sent to tear down the connection. |burst| and |
| 3255 | + * |rate| default to 1000 and 33 respectively. |
| 3256 | + */ |
| 3257 | +NGHTTP2_EXTERN void nghttp2_option_set_glitch_rate_limit(nghttp2_option *option, |
| 3258 | + uint64_t burst, |
| 3259 | + uint64_t rate); |
| 3260 | + |
3221 | 3261 | /** |
3222 | 3262 | * @function |
3223 | 3263 | * |
|