1 | // version, status code, and reason phrase |
2 | fn parse_status_line(line string) !(string, int, string) { |
3 | if line.len < 5 || line[..5].to_lower() != 'http/' { |
4 | - return error('response does not start with HTTP/') |
5 | + return error('response does not start with HTTP/, line: `${line}`') |
6 | } |
7 | data := line.split_nth(' ', 3) |
8 | if data.len != 3 { |
9 | - return error('expected at least 3 tokens') |
10 | + return error('expected at least 3 tokens, but found: ${data.len}') |
11 | } |
12 | version := data[0].substr(5, data[0].len) |
13 | // validate version is 1*DIGIT "." 1*DIGIT |
14 | digits := version.split_nth('.', 3) |
15 | if digits.len != 2 { |
16 | - return error('HTTP version malformed') |
17 | + return error('HTTP version malformed, found: `${digits}`') |
18 | } |
19 | for digit in digits { |
20 | - strconv.atoi(digit) or { return error('HTTP version must contain only integers') } |
21 | + strconv.atoi(digit) or { |
22 | + return error('HTTP version must contain only integers, found: `${digit}`') |
23 | + } |
24 | } |
25 | return version, strconv.atoi(data[1])!, data[2] |
26 | } |
27 | |