From a932a8b1ea656156af6a823dedde8388f9b81766 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Tue, 31 Jan 2023 15:11:21 +0200 Subject: [PATCH] net.http: make the errors that parse_status_line returns more informative to make diagnosing problems easier --- vlib/net/http/response.v | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/vlib/net/http/response.v b/vlib/net/http/response.v index 76bd7c8d1..cf6318a49 100644 --- a/vlib/net/http/response.v +++ b/vlib/net/http/response.v @@ -58,20 +58,22 @@ pub fn parse_response(resp string) !Response { // version, status code, and reason phrase fn parse_status_line(line string) !(string, int, string) { if line.len < 5 || line[..5].to_lower() != 'http/' { - return error('response does not start with HTTP/') + return error('response does not start with HTTP/, line: `${line}`') } data := line.split_nth(' ', 3) if data.len != 3 { - return error('expected at least 3 tokens') + return error('expected at least 3 tokens, but found: ${data.len}') } version := data[0].substr(5, data[0].len) // validate version is 1*DIGIT "." 1*DIGIT digits := version.split_nth('.', 3) if digits.len != 2 { - return error('HTTP version malformed') + return error('HTTP version malformed, found: `${digits}`') } for digit in digits { - strconv.atoi(digit) or { return error('HTTP version must contain only integers') } + strconv.atoi(digit) or { + return error('HTTP version must contain only integers, found: `${digit}`') + } } return version, strconv.atoi(data[1])!, data[2] } -- 2.30.2