4 ms·
It's been a while since I have C/C++'d so some of my terminology is probably wrong. ngx_http_v2_parse_method iterates through all the tests, starting with the
by Brybry 5y ago
It's been a while since I have C/C++'d so some of my terminology is probably wrong.
ngx_http_v2_parse_method iterates through all the tests, starting with the first test (GET).
They compare request method string length to test string length then on matching lengths compare each character in the request method string to the test string.
Fully matching strings set the request method numerical value from the test value and returns OK.
Any non-matching characters GOTO the next test.
After that it does a sanity check on the request method string characters (A to Z or _ or -) and returns OK or DECLINED as appropriate.
For the macros defining the HTTP method numerical values I think they're set up that way as bitmasks for bitwise operations.
For example, they do things like[1]
if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD)))
Here HTTP request method value is bitwise AND against (0x00000002 OR 0x00000004)
Any non-zero value here would be true and any zero value is false.
So if the request method bit value AND matches either GET or HEAD bits then this conditional is false.
[1] https://github.com/nginx/nginx/blob/a64190933e06758d50eea926e6a55974645096fd/src/http/modules/ngx_http_stub_status_module.c#L92 https://github.com/nginx/nginx/blob/a64190933e06758d50eea926...