1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

all: change optional to result of io (#16075)

This commit is contained in:
yuyi
2022-10-16 14:28:57 +08:00
committed by GitHub
parent 6e46933c55
commit f6844e9766
187 changed files with 1885 additions and 1874 deletions

View File

@@ -35,11 +35,11 @@ pub fn (resp Response) bytestr() string {
}
// Parse a raw HTTP response into a Response object
pub fn parse_response(resp string) ?Response {
version, status_code, status_msg := parse_status_line(resp.all_before('\n'))?
pub fn parse_response(resp string) !Response {
version, status_code, status_msg := parse_status_line(resp.all_before('\n'))!
// Build resp header map and separate the body
start_idx, end_idx := find_headers_range(resp)?
header := parse_headers(resp.substr(start_idx, end_idx))?
start_idx, end_idx := find_headers_range(resp)!
header := parse_headers(resp.substr(start_idx, end_idx))!
mut body := resp.substr(end_idx, resp.len)
if header.get(.transfer_encoding) or { '' } == 'chunked' {
body = chunked.decode(body)
@@ -56,7 +56,7 @@ pub fn parse_response(resp string) ?Response {
// parse_status_line parses the first HTTP response line into the HTTP
// version, status code, and reason phrase
fn parse_status_line(line string) ?(string, int, string) {
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/')
}
@@ -73,7 +73,7 @@ fn parse_status_line(line string) ?(string, int, string) {
for digit in digits {
strconv.atoi(digit) or { return error('HTTP version must contain only integers') }
}
return version, strconv.atoi(data[1])?, data[2]
return version, strconv.atoi(data[1])!, data[2]
}
// cookies parses the Set-Cookie headers into Cookie objects
@@ -138,7 +138,7 @@ pub fn new_response(conf ResponseConfig) Response {
// index of the headers in the string, including the trailing newlines. This
// helper function expects the first line in `data` to be the HTTP status line
// (HTTP/1.1 200 OK).
fn find_headers_range(data string) ?(int, int) {
fn find_headers_range(data string) !(int, int) {
start_idx := data.index('\n') or { return error('no start index found') } + 1
mut count := 0
for i := start_idx; i < data.len; i++ {