From 977cbff80d45f479e8fc20ab2b18979b6d17a819 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Tue, 16 Jul 2024 17:36:04 +0300 Subject: Fix http_service::post() to skip potential CONNECT response --- bdep/http-service.cxx | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) 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 (move (r)); }; - while (!(l = curl::read_http_response_line (is)).empty ()) + auto parse_header = [&ctype, &location, &rs, &header] () { if (optional 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. -- cgit v1.1