jeremycw / httpserver.h

Single header library for writing non-blocking HTTP servers in C
MIT License
1.78k stars 143 forks source link

Wrong behaviour of the http_request_header function #45

Closed egorsmkv closed 3 years ago

egorsmkv commented 3 years ago

I am coding the following:

        http_string_t path = http_request_header(request, "x-file-path");
        http_string_t output_path = http_request_header(request, "x-output-path");

but getting wrong values from these variables, for example:

        sds path_str = sdstrim(sdsnew(path.buf), "\n\r");
        log_debug("Path: %s", path_str);
curl -vvvv  -H "X-File-Path: /home/yehor/i_1.raw" -H "X-Output-Path: /home/yehor/test1" http://localhost:8080/task
2020-09-15 13:22:54.7908 DEBUG [rest.denoiser] Path: /home/yehor/i_1.raw
X-Output-Path: /home/yehor/test1
jeremycw commented 3 years ago

http_string_t will not be null terminated. You need to use the len field along with buf to read it. This could probably be clearer in the documentation.