3 ms·
Nice! I can't be the only one who went looking and spent way to much time trying to acquaint myself with c++ :) Here's there I ended up: https://github.com/ngi
by patcon 5y ago
Nice! I can't be the only one who went looking and spent way to much time trying to acquaint myself with c++ :)
Here's there I ended up: https://github.com/nginx/nginx/blob/363505e806feebb7ceb1f9edb0e3f75c1253384f/src/http/v2/ngx_http_v2.c#L3580 https://github.com/nginx/nginx/blob/363505e806feebb7ceb1f9ed...
PS, I'm not totally sure, but they definitely use the count of letters as an optimization, and it seems they increment the bits associated with each type, so the order of the bits behind each NGX_HTTP_GET etc seems to matter...!
https://github.com/nginx/nginx/blob/67d160bf25e02ba6679bb6c3b9cbdfeb29b759de/src/http/ngx_http_request.h#L28-L44 https://github.com/nginx/nginx/blob/67d160bf25e02ba6679bb6c3...
Someday I will understand :)
- Brybry 5y agoIt'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...