diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2024-07-16 17:36:04 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2024-07-16 22:37:51 +0300 |
commit | 977cbff80d45f479e8fc20ab2b18979b6d17a819 (patch) | |
tree | 55c032cb50a5ced5828a80337381820b83fadfa1 | |
parent | a1737cd518e8b25367efe33252a18b9b9e03c9ce (diff) |
Fix http_service::post() to skip potential CONNECT response
-rw-r--r-- | bdep/http-service.cxx | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/bdep/http-service.cxx b/bdep/http-service.cxx index 63e1e59..c967b1f 100644 --- a/bdep/http-service.cxx +++ b/bdep/http-service.cxx @@ -231,7 +231,7 @@ namespace bdep return optional<string> (move (r)); }; - while (!(l = curl::read_http_response_line (is)).empty ()) + auto parse_header = [&ctype, &location, &rs, &header] () { if (optional<string> v = header ("Content-Type")) ctype = move (v); @@ -249,6 +249,36 @@ namespace bdep // } } + }; + + // Note that the curl's output may include the CONNECT response (see + // curl::read_http_status() for details). If that's the case, then + // skip it, similar to curl::read_http_status(). + // + bool content_expected (false); + while (!(l = curl::read_http_response_line (is)).empty ()) + { + if (curl::http_content_aspect (l)) + content_expected = true; + + parse_header (); + } + + if (rs.code == 200 && !content_expected) + { + try + { + rs = curl::read_http_status (is, false /* skip_headers */); + } + catch (const invalid_argument& e) + { + bad_response ( + string ("unable to read proxied HTTP response status line: ") + + e.what ()); + } + + while (!(l = curl::read_http_response_line (is)).empty ()) + parse_header (); } assert (!eof (is)); // Would have already failed otherwise. |