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

48 lines
1.3 KiB
V
Raw Normal View History

2022-01-04 12:21:08 +03:00
// Copyright (c) 2019-2022 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
module http
import net.ssl
2019-11-24 06:27:02 +03:00
import strings
fn (req &Request) ssl_do(port int, method Method, host_name string, path string) !Response {
mut ssl_conn := ssl.new_ssl_conn(
verify: req.verify
cert: req.cert
cert_key: req.cert_key
validate: req.validate
in_memory_verification: req.in_memory_verification
)!
ssl_conn.dial(host_name, port) or { return err }
req_headers := req.build_request_headers(method, host_name, path)
$if trace_http_request ? {
eprintln('> $req_headers')
}
// println(req_headers)
ssl_conn.write_string(req_headers) or { return err }
mut content := strings.new_builder(100)
2022-04-15 15:57:45 +03:00
mut buff := [bufsize]u8{}
bp := unsafe { &buff[0] }
mut readcounter := 0
for {
readcounter++
len := ssl_conn.socket_read_into_ptr(bp, bufsize) or { break }
$if debug_http ? {
eprintln('ssl_do, read ${readcounter:4d} | len: $len')
eprintln('-'.repeat(20))
eprintln(unsafe { tos(bp, len) })
eprintln('-'.repeat(20))
}
unsafe { content.write_ptr(bp, len) }
2019-11-24 06:27:02 +03:00
}
ssl_conn.shutdown()!
response_text := content.str()
$if trace_http_response ? {
eprintln('< $response_text')
}
return parse_response(response_text)
}