mirror of
https://github.com/vlang/v.git
synced 2025-09-14 06:52:36 +03:00
fmt: fix alignment of struct init fields (#22025)
This commit is contained in:
parent
99da5726db
commit
c51d30bf53
671 changed files with 18817 additions and 18787 deletions
|
@ -15,10 +15,10 @@ fn (req &Request) ssl_do(port int, method Method, host_name string, path string)
|
|||
|
||||
fn net_ssl_do(req &Request, 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
|
||||
verify: req.verify
|
||||
cert: req.cert
|
||||
cert_key: req.cert_key
|
||||
validate: req.validate
|
||||
in_memory_verification: req.in_memory_verification
|
||||
)!
|
||||
mut retries := 0
|
||||
|
|
|
@ -58,7 +58,7 @@ fn (mut s ChunkScanner) read_chunk(chunksize u32) !string {
|
|||
pub fn decode(text string) !string {
|
||||
mut sb := strings.new_builder(100)
|
||||
mut cscanner := ChunkScanner{
|
||||
pos: 0
|
||||
pos: 0
|
||||
text: text
|
||||
}
|
||||
for {
|
||||
|
|
|
@ -82,7 +82,7 @@ pub fn read_cookies(h Header, filter string) []&Cookie {
|
|||
}
|
||||
val = parse_cookie_value(val, true) or { continue }
|
||||
cookies << &Cookie{
|
||||
name: name
|
||||
name: name
|
||||
value: val
|
||||
}
|
||||
}
|
||||
|
@ -324,9 +324,9 @@ fn parse_cookie(line string) !Cookie {
|
|||
}
|
||||
value := parse_cookie_value(raw_value, true) or { return error('malformed cookie') }
|
||||
mut c := Cookie{
|
||||
name: name
|
||||
name: name
|
||||
value: value
|
||||
raw: line
|
||||
raw: line
|
||||
}
|
||||
for i, _ in parts {
|
||||
parts[i] = parts[i].trim_space()
|
||||
|
|
|
@ -18,47 +18,47 @@ struct AddCookieTestCase {
|
|||
const write_set_cookie_tests = [
|
||||
SetCookieTestCase{
|
||||
cookie: &http.Cookie{
|
||||
name: 'cookie-1'
|
||||
name: 'cookie-1'
|
||||
value: 'v1'
|
||||
}
|
||||
raw: 'cookie-1=v1'
|
||||
},
|
||||
SetCookieTestCase{
|
||||
cookie: &http.Cookie{
|
||||
name: 'cookie-2'
|
||||
value: 'two'
|
||||
name: 'cookie-2'
|
||||
value: 'two'
|
||||
max_age: 3600
|
||||
}
|
||||
raw: 'cookie-2=two; Max-Age=3600'
|
||||
},
|
||||
SetCookieTestCase{
|
||||
cookie: &http.Cookie{
|
||||
name: 'cookie-3'
|
||||
value: 'three'
|
||||
name: 'cookie-3'
|
||||
value: 'three'
|
||||
domain: '.example.com'
|
||||
}
|
||||
raw: 'cookie-3=three; domain=example.com'
|
||||
},
|
||||
SetCookieTestCase{
|
||||
cookie: &http.Cookie{
|
||||
name: 'cookie-4'
|
||||
name: 'cookie-4'
|
||||
value: 'four'
|
||||
path: '/restricted/'
|
||||
path: '/restricted/'
|
||||
}
|
||||
raw: 'cookie-4=four; path=/restricted/'
|
||||
},
|
||||
SetCookieTestCase{
|
||||
cookie: &http.Cookie{
|
||||
name: 'cookie-5'
|
||||
value: 'five'
|
||||
name: 'cookie-5'
|
||||
value: 'five'
|
||||
domain: 'wrong;bad.abc'
|
||||
}
|
||||
raw: 'cookie-5=five'
|
||||
},
|
||||
SetCookieTestCase{
|
||||
cookie: &http.Cookie{
|
||||
name: 'cookie-6'
|
||||
value: 'six'
|
||||
name: 'cookie-6'
|
||||
value: 'six'
|
||||
domain: 'bad-.abc'
|
||||
}
|
||||
raw: 'cookie-6=six'
|
||||
|
@ -69,8 +69,8 @@ const write_set_cookie_tests = [
|
|||
// },
|
||||
SetCookieTestCase{
|
||||
cookie: &http.Cookie{
|
||||
name: 'cookie-8'
|
||||
value: 'eight'
|
||||
name: 'cookie-8'
|
||||
value: 'eight'
|
||||
domain: '::1'
|
||||
}
|
||||
raw: 'cookie-8=eight'
|
||||
|
@ -90,32 +90,32 @@ const write_set_cookie_tests = [
|
|||
// },
|
||||
SetCookieTestCase{
|
||||
cookie: &http.Cookie{
|
||||
name: 'cookie-12'
|
||||
value: 'samesite-default'
|
||||
name: 'cookie-12'
|
||||
value: 'samesite-default'
|
||||
same_site: .same_site_default_mode
|
||||
}
|
||||
raw: 'cookie-12=samesite-default; SameSite'
|
||||
},
|
||||
SetCookieTestCase{
|
||||
cookie: &http.Cookie{
|
||||
name: 'cookie-13'
|
||||
value: 'samesite-lax'
|
||||
name: 'cookie-13'
|
||||
value: 'samesite-lax'
|
||||
same_site: .same_site_lax_mode
|
||||
}
|
||||
raw: 'cookie-13=samesite-lax; SameSite=Lax'
|
||||
},
|
||||
SetCookieTestCase{
|
||||
cookie: &http.Cookie{
|
||||
name: 'cookie-14'
|
||||
value: 'samesite-strict'
|
||||
name: 'cookie-14'
|
||||
value: 'samesite-strict'
|
||||
same_site: .same_site_strict_mode
|
||||
}
|
||||
raw: 'cookie-14=samesite-strict; SameSite=Strict'
|
||||
},
|
||||
SetCookieTestCase{
|
||||
cookie: &http.Cookie{
|
||||
name: 'cookie-15'
|
||||
value: 'samesite-none'
|
||||
name: 'cookie-15'
|
||||
value: 'samesite-none'
|
||||
same_site: .same_site_none_mode
|
||||
}
|
||||
raw: 'cookie-15=samesite-none; SameSite=None'
|
||||
|
@ -124,63 +124,63 @@ const write_set_cookie_tests = [
|
|||
// are disallowed by RFC 6265 but are common in the wild.
|
||||
SetCookieTestCase{
|
||||
cookie: &http.Cookie{
|
||||
name: 'special-1'
|
||||
name: 'special-1'
|
||||
value: 'a z'
|
||||
}
|
||||
raw: 'special-1=a z'
|
||||
},
|
||||
SetCookieTestCase{
|
||||
cookie: &http.Cookie{
|
||||
name: 'special-2'
|
||||
name: 'special-2'
|
||||
value: ' z'
|
||||
}
|
||||
raw: 'special-2=" z"'
|
||||
},
|
||||
SetCookieTestCase{
|
||||
cookie: &http.Cookie{
|
||||
name: 'special-3'
|
||||
name: 'special-3'
|
||||
value: 'a '
|
||||
}
|
||||
raw: 'special-3="a "'
|
||||
},
|
||||
SetCookieTestCase{
|
||||
cookie: &http.Cookie{
|
||||
name: 'special-4'
|
||||
name: 'special-4'
|
||||
value: ' '
|
||||
}
|
||||
raw: 'special-4=" "'
|
||||
},
|
||||
SetCookieTestCase{
|
||||
cookie: &http.Cookie{
|
||||
name: 'special-5'
|
||||
name: 'special-5'
|
||||
value: 'a,z'
|
||||
}
|
||||
raw: 'special-5=a,z'
|
||||
},
|
||||
SetCookieTestCase{
|
||||
cookie: &http.Cookie{
|
||||
name: 'special-6'
|
||||
name: 'special-6'
|
||||
value: ',z'
|
||||
}
|
||||
raw: 'special-6=",z"'
|
||||
},
|
||||
SetCookieTestCase{
|
||||
cookie: &http.Cookie{
|
||||
name: 'special-7'
|
||||
name: 'special-7'
|
||||
value: 'a,'
|
||||
}
|
||||
raw: 'special-7="a,"'
|
||||
},
|
||||
SetCookieTestCase{
|
||||
cookie: &http.Cookie{
|
||||
name: 'special-8'
|
||||
name: 'special-8'
|
||||
value: ','
|
||||
}
|
||||
raw: 'special-8=","'
|
||||
},
|
||||
SetCookieTestCase{
|
||||
cookie: &http.Cookie{
|
||||
name: 'empty-value'
|
||||
name: 'empty-value'
|
||||
value: ''
|
||||
}
|
||||
raw: 'empty-value='
|
||||
|
@ -205,21 +205,21 @@ const write_set_cookie_tests = [
|
|||
},
|
||||
SetCookieTestCase{
|
||||
cookie: &http.Cookie{
|
||||
name: 'a\nb'
|
||||
name: 'a\nb'
|
||||
value: 'v'
|
||||
}
|
||||
raw: ''
|
||||
},
|
||||
SetCookieTestCase{
|
||||
cookie: &http.Cookie{
|
||||
name: 'a\nb'
|
||||
name: 'a\nb'
|
||||
value: 'v'
|
||||
}
|
||||
raw: ''
|
||||
},
|
||||
SetCookieTestCase{
|
||||
cookie: &http.Cookie{
|
||||
name: 'a\rb'
|
||||
name: 'a\rb'
|
||||
value: 'v'
|
||||
}
|
||||
raw: ''
|
||||
|
@ -228,25 +228,25 @@ const write_set_cookie_tests = [
|
|||
const add_cookies_tests = [
|
||||
AddCookieTestCase{
|
||||
cookie: []
|
||||
raw: ''
|
||||
raw: ''
|
||||
},
|
||||
AddCookieTestCase{
|
||||
cookie: [&http.Cookie{
|
||||
name: 'cookie-1'
|
||||
name: 'cookie-1'
|
||||
value: 'v1'
|
||||
}]
|
||||
raw: 'cookie-1=v1'
|
||||
},
|
||||
AddCookieTestCase{
|
||||
cookie: [&http.Cookie{
|
||||
name: 'cookie-1'
|
||||
name: 'cookie-1'
|
||||
value: 'v1'
|
||||
}, &http.Cookie{
|
||||
name: 'cookie-2'
|
||||
name: 'cookie-2'
|
||||
value: 'v2'
|
||||
},
|
||||
&http.Cookie{
|
||||
name: 'cookie-3'
|
||||
name: 'cookie-3'
|
||||
value: 'v3'
|
||||
}]
|
||||
raw: 'cookie-1=v1; cookie-2=v2; cookie-3=v3'
|
||||
|
|
|
@ -20,9 +20,9 @@ fn path_to_entity(path string, uri_path string) Entity {
|
|||
fname := os.file_name(path)
|
||||
return Entity{
|
||||
FileInfo: pinfo
|
||||
path: path
|
||||
path: path
|
||||
mod_time: time.unix(pinfo.mtime)
|
||||
url: '${uri_base}/${fname}'
|
||||
fname: fname
|
||||
url: '${uri_base}/${fname}'
|
||||
fname: fname
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ pub fn serve(params StaticServeParams) {
|
|||
handler: StaticHttpHandler{
|
||||
params: nparams
|
||||
}
|
||||
addr: params.on
|
||||
addr: params.on
|
||||
worker_num: params.workers
|
||||
}
|
||||
if params.shutdown_after != time.infinite {
|
||||
|
|
|
@ -736,7 +736,7 @@ pub fn (h Header) render_into_sb(mut sb strings.Builder, flags HeaderRenderConfi
|
|||
// join combines two Header structs into a new Header struct
|
||||
pub fn (h Header) join(other Header) Header {
|
||||
mut combined := Header{
|
||||
data: h.data // h.data.clone()
|
||||
data: h.data // h.data.clone()
|
||||
cur_pos: h.cur_pos
|
||||
}
|
||||
for k in other.keys() {
|
||||
|
@ -793,16 +793,16 @@ fn is_valid(header string) ! {
|
|||
for _, c in header {
|
||||
if int(c) >= 128 || !is_token(c) {
|
||||
return HeaderKeyError{
|
||||
code: 1
|
||||
header: header
|
||||
code: 1
|
||||
header: header
|
||||
invalid_char: c
|
||||
}
|
||||
}
|
||||
}
|
||||
if header.len == 0 {
|
||||
return HeaderKeyError{
|
||||
code: 2
|
||||
header: header
|
||||
code: 2
|
||||
header: header
|
||||
invalid_char: 0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ module http
|
|||
|
||||
fn test_header_new() {
|
||||
h := new_header(HeaderConfig{ key: .accept, value: 'nothing' },
|
||||
key: .expires
|
||||
key: .expires
|
||||
value: 'yesterday'
|
||||
)
|
||||
assert h.contains(.accept)
|
||||
|
@ -50,7 +50,7 @@ fn test_header_get() {
|
|||
|
||||
fn test_header_set() {
|
||||
mut h := new_header(HeaderConfig{ key: .dnt, value: 'one' },
|
||||
key: .dnt
|
||||
key: .dnt
|
||||
value: 'two'
|
||||
)
|
||||
assert h.values(.dnt) == ['one', 'two']
|
||||
|
@ -60,7 +60,7 @@ fn test_header_set() {
|
|||
|
||||
fn test_header_delete() {
|
||||
mut h := new_header(HeaderConfig{ key: .dnt, value: 'one' },
|
||||
key: .dnt
|
||||
key: .dnt
|
||||
value: 'two'
|
||||
)
|
||||
assert h.values(.dnt) == ['one', 'two']
|
||||
|
|
|
@ -49,8 +49,8 @@ pub fn new_request(method Method, url_ string, data string) Request {
|
|||
// println('new req() method=$method url="$url" dta="$data"')
|
||||
return Request{
|
||||
method: method
|
||||
url: url
|
||||
data: data
|
||||
url: url
|
||||
data: data
|
||||
/*
|
||||
headers: {
|
||||
'Accept-Encoding': 'compress'
|
||||
|
@ -68,8 +68,8 @@ pub fn get(url string) !Response {
|
|||
pub fn post(url string, data string) !Response {
|
||||
return fetch(
|
||||
method: .post
|
||||
url: url
|
||||
data: data
|
||||
url: url
|
||||
data: data
|
||||
header: new_header(key: .content_type, value: http.content_type_default)
|
||||
)
|
||||
}
|
||||
|
@ -78,8 +78,8 @@ pub fn post(url string, data string) !Response {
|
|||
pub fn post_json(url string, data string) !Response {
|
||||
return fetch(
|
||||
method: .post
|
||||
url: url
|
||||
data: data
|
||||
url: url
|
||||
data: data
|
||||
header: new_header(key: .content_type, value: 'application/json')
|
||||
)
|
||||
}
|
||||
|
@ -89,18 +89,18 @@ pub fn post_json(url string, data string) !Response {
|
|||
pub fn post_form(url string, data map[string]string) !Response {
|
||||
return fetch(
|
||||
method: .post
|
||||
url: url
|
||||
url: url
|
||||
header: new_header(key: .content_type, value: 'application/x-www-form-urlencoded')
|
||||
data: url_encode_form_data(data)
|
||||
data: url_encode_form_data(data)
|
||||
)
|
||||
}
|
||||
|
||||
pub fn post_form_with_cookies(url string, data map[string]string, cookies map[string]string) !Response {
|
||||
return fetch(
|
||||
method: .post
|
||||
url: url
|
||||
header: new_header(key: .content_type, value: 'application/x-www-form-urlencoded')
|
||||
data: url_encode_form_data(data)
|
||||
method: .post
|
||||
url: url
|
||||
header: new_header(key: .content_type, value: 'application/x-www-form-urlencoded')
|
||||
data: url_encode_form_data(data)
|
||||
cookies: cookies
|
||||
)
|
||||
}
|
||||
|
@ -122,9 +122,9 @@ pub fn post_multipart_form(url string, conf PostMultipartFormConfig) !Response {
|
|||
header.set(.content_type, 'multipart/form-data; boundary="${boundary}"')
|
||||
return fetch(
|
||||
method: .post
|
||||
url: url
|
||||
url: url
|
||||
header: header
|
||||
data: body
|
||||
data: body
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -132,8 +132,8 @@ pub fn post_multipart_form(url string, conf PostMultipartFormConfig) !Response {
|
|||
pub fn put(url string, data string) !Response {
|
||||
return fetch(
|
||||
method: .put
|
||||
url: url
|
||||
data: data
|
||||
url: url
|
||||
data: data
|
||||
header: new_header(key: .content_type, value: http.content_type_default)
|
||||
)
|
||||
}
|
||||
|
@ -142,8 +142,8 @@ pub fn put(url string, data string) !Response {
|
|||
pub fn patch(url string, data string) !Response {
|
||||
return fetch(
|
||||
method: .patch
|
||||
url: url
|
||||
data: data
|
||||
url: url
|
||||
data: data
|
||||
header: new_header(key: .content_type, value: http.content_type_default)
|
||||
)
|
||||
}
|
||||
|
@ -167,28 +167,28 @@ pub fn prepare(config FetchConfig) !Request {
|
|||
}
|
||||
url := build_url_from_fetch(config) or { return error('http.fetch: invalid url ${config.url}') }
|
||||
req := Request{
|
||||
method: config.method
|
||||
url: url
|
||||
data: config.data
|
||||
header: config.header
|
||||
cookies: config.cookies
|
||||
user_agent: config.user_agent
|
||||
user_ptr: config.user_ptr
|
||||
verbose: config.verbose
|
||||
validate: config.validate
|
||||
verify: config.verify
|
||||
cert: config.cert
|
||||
proxy: config.proxy
|
||||
cert_key: config.cert_key
|
||||
method: config.method
|
||||
url: url
|
||||
data: config.data
|
||||
header: config.header
|
||||
cookies: config.cookies
|
||||
user_agent: config.user_agent
|
||||
user_ptr: config.user_ptr
|
||||
verbose: config.verbose
|
||||
validate: config.validate
|
||||
verify: config.verify
|
||||
cert: config.cert
|
||||
proxy: config.proxy
|
||||
cert_key: config.cert_key
|
||||
in_memory_verification: config.in_memory_verification
|
||||
allow_redirect: config.allow_redirect
|
||||
max_retries: config.max_retries
|
||||
on_progress: config.on_progress
|
||||
on_progress_body: config.on_progress_body
|
||||
on_redirect: config.on_redirect
|
||||
on_finish: config.on_finish
|
||||
stop_copying_limit: config.stop_copying_limit
|
||||
stop_receiving_limit: config.stop_receiving_limit
|
||||
allow_redirect: config.allow_redirect
|
||||
max_retries: config.max_retries
|
||||
on_progress: config.on_progress
|
||||
on_progress_body: config.on_progress_body
|
||||
on_redirect: config.on_redirect
|
||||
on_finish: config.on_finish
|
||||
stop_copying_limit: config.stop_copying_limit
|
||||
stop_receiving_limit: config.stop_receiving_limit
|
||||
}
|
||||
return req
|
||||
}
|
||||
|
|
|
@ -51,13 +51,13 @@ pub fn new_http_proxy(raw_url string) !&HttpProxy {
|
|||
}
|
||||
|
||||
return &HttpProxy{
|
||||
scheme: scheme
|
||||
scheme: scheme
|
||||
username: url.user.username
|
||||
password: url.user.password
|
||||
host: host
|
||||
host: host
|
||||
hostname: url.hostname()
|
||||
port: port
|
||||
url: str_url
|
||||
port: port
|
||||
url: str_url
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,10 +151,10 @@ fn (pr &HttpProxy) ssl_dial(host string) !&ssl.SSLConn {
|
|||
}
|
||||
|
||||
mut ssl_conn := ssl.new_ssl_conn(
|
||||
verify: ''
|
||||
cert: ''
|
||||
cert_key: ''
|
||||
validate: false
|
||||
verify: ''
|
||||
cert: ''
|
||||
cert_key: ''
|
||||
validate: false
|
||||
in_memory_verification: false
|
||||
)!
|
||||
ssl_conn.connect(mut tcp, host.all_before_last(':'))!
|
||||
|
|
14122
vlib/net/http/mime/db.v
14122
vlib/net/http/mime/db.v
File diff suppressed because it is too large
Load diff
|
@ -2,20 +2,20 @@ module mime
|
|||
|
||||
fn test_mime() {
|
||||
assert get_complete_mime_type('application/json') == MimeType{
|
||||
source: 'iana'
|
||||
extensions: ['json', 'map']
|
||||
source: 'iana'
|
||||
extensions: ['json', 'map']
|
||||
compressible: true
|
||||
charset: 'UTF-8'
|
||||
charset: 'UTF-8'
|
||||
}
|
||||
assert get_mime_type('json') == 'application/json'
|
||||
assert get_content_type('application/json') == 'application/json; charset=utf-8'
|
||||
assert get_default_ext('application/json') == 'json'
|
||||
|
||||
assert get_complete_mime_type('text/markdown') == MimeType{
|
||||
source: 'iana'
|
||||
extensions: ['md', 'markdown']
|
||||
source: 'iana'
|
||||
extensions: ['md', 'markdown']
|
||||
compressible: true
|
||||
charset: ''
|
||||
charset: ''
|
||||
}
|
||||
assert get_mime_type('md') == 'text/markdown'
|
||||
assert get_content_type('text/markdown') == 'text/markdown; charset=utf-8'
|
||||
|
|
|
@ -84,7 +84,7 @@ pub fn (req &Request) cookie(name string) ?Cookie {
|
|||
|
||||
if value := req.cookies[name] {
|
||||
return Cookie{
|
||||
name: name
|
||||
name: name
|
||||
value: value
|
||||
}
|
||||
}
|
||||
|
@ -417,10 +417,10 @@ pub fn parse_request_head(mut reader io.BufferedReader) !Request {
|
|||
}
|
||||
|
||||
return Request{
|
||||
method: method
|
||||
url: target.str()
|
||||
header: header
|
||||
host: header.get(.host) or { '' }
|
||||
method: method
|
||||
url: target.str()
|
||||
header: header
|
||||
host: header.get(.host) or { '' }
|
||||
version: version
|
||||
cookies: request_cookies
|
||||
}
|
||||
|
@ -602,9 +602,9 @@ pub fn parse_multipart_form(body string, boundary string) (map[string]string, ma
|
|||
// dump(data.limit(20).bytes())
|
||||
// dump(data.len)
|
||||
files[name] << FileData{
|
||||
filename: filename
|
||||
filename: filename
|
||||
content_type: content_type
|
||||
data: data
|
||||
data: data
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -142,9 +142,9 @@ ${contents[1]}\r
|
|||
assert files == {
|
||||
names[0]: [
|
||||
FileData{
|
||||
filename: file
|
||||
filename: file
|
||||
content_type: ct
|
||||
data: contents[0]
|
||||
data: contents[0]
|
||||
},
|
||||
]
|
||||
}
|
||||
|
@ -180,9 +180,9 @@ fn test_multipart_form_body() {
|
|||
files := {
|
||||
'foo': [
|
||||
FileData{
|
||||
filename: 'bar.v'
|
||||
filename: 'bar.v'
|
||||
content_type: 'application/octet-stream'
|
||||
data: 'baz'
|
||||
data: 'baz'
|
||||
},
|
||||
]
|
||||
}
|
||||
|
|
|
@ -45,10 +45,10 @@ pub fn parse_response(resp string) !Response {
|
|||
}
|
||||
return Response{
|
||||
http_version: version
|
||||
status_code: status_code
|
||||
status_msg: status_msg
|
||||
header: header
|
||||
body: body
|
||||
status_code: status_code
|
||||
status_msg: status_msg
|
||||
header: header
|
||||
body: body
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,7 +128,7 @@ pub:
|
|||
// function will add a Content-Length header if body is not empty.
|
||||
pub fn new_response(conf ResponseConfig) Response {
|
||||
mut resp := Response{
|
||||
body: conf.body
|
||||
body: conf.body
|
||||
header: conf.header
|
||||
}
|
||||
if resp.body != '' && !resp.header.contains(.content_length) {
|
||||
|
|
|
@ -3,7 +3,7 @@ module http
|
|||
fn test_response_bytestr_1() {
|
||||
resp := new_response(
|
||||
status: .ok
|
||||
body: 'Foo'
|
||||
body: 'Foo'
|
||||
)
|
||||
assert resp.bytestr() == 'HTTP/1.1 200 OK\r\n' + 'Content-Length: 3\r\n' + '\r\n' + 'Foo'
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ fn test_response_bytestr_1() {
|
|||
fn test_response_bytestr_2() {
|
||||
resp := new_response(
|
||||
status: .found
|
||||
body: 'Foo'
|
||||
body: 'Foo'
|
||||
header: new_header(key: .location, value: '/')
|
||||
)
|
||||
lines := resp.bytestr().split_into_lines()
|
||||
|
|
|
@ -174,8 +174,8 @@ pub mut:
|
|||
|
||||
fn new_handler_worker(wid int, ch chan &net.TcpConn, handler Handler) thread {
|
||||
mut w := &HandlerWorker{
|
||||
id: wid
|
||||
ch: ch
|
||||
id: wid
|
||||
ch: ch
|
||||
handler: handler
|
||||
}
|
||||
return spawn w.process_requests()
|
||||
|
@ -234,7 +234,7 @@ fn (d DebugHandler) handle(req Request) Response {
|
|||
eprintln('[${time.now()}] ${req.method} ${req.url} - 200')
|
||||
}
|
||||
mut r := Response{
|
||||
body: req.data
|
||||
body: req.data
|
||||
header: req.header
|
||||
}
|
||||
r.set_status(.ok)
|
||||
|
|
|
@ -37,8 +37,8 @@ fn test_server_close() {
|
|||
log.warn('${@FN} finished')
|
||||
}
|
||||
mut server := &http.Server{
|
||||
accept_timeout: atimeout
|
||||
handler: MyHttpHandler{}
|
||||
accept_timeout: atimeout
|
||||
handler: MyHttpHandler{}
|
||||
show_startup_message: false
|
||||
}
|
||||
t := spawn server.listen_and_serve()
|
||||
|
@ -58,8 +58,8 @@ fn test_server_custom_listener() {
|
|||
}
|
||||
listener := net.listen_tcp(.ip6, ':8081')!
|
||||
mut server := &http.Server{
|
||||
accept_timeout: atimeout
|
||||
listener: listener
|
||||
accept_timeout: atimeout
|
||||
listener: listener
|
||||
show_startup_message: false
|
||||
}
|
||||
t := spawn server.listen_and_serve()
|
||||
|
@ -84,7 +84,7 @@ fn (mut handler MyHttpHandler) handle(req http.Request) http.Response {
|
|||
handler.counter++
|
||||
// eprintln('$time.now() | counter: $handler.counter | $req.method $req.url\n$req.header\n$req.data - 200 OK\n')
|
||||
mut r := http.Response{
|
||||
body: req.data + ', ${req.url}'
|
||||
body: req.data + ', ${req.url}'
|
||||
header: req.header
|
||||
}
|
||||
match req.url.all_before('?') {
|
||||
|
@ -120,8 +120,8 @@ fn test_server_custom_handler() {
|
|||
mut handler := MyHttpHandler{}
|
||||
mut server := &http.Server{
|
||||
accept_timeout: atimeout
|
||||
handler: handler
|
||||
addr: ':18197'
|
||||
handler: handler
|
||||
addr: ':18197'
|
||||
}
|
||||
t := spawn server.listen_and_serve()
|
||||
server.wait_till_running()!
|
||||
|
@ -142,8 +142,8 @@ fn test_server_custom_handler() {
|
|||
big_url := 'http://${server.addr}/redirect_to_big'
|
||||
mut progress_calls := &ProgressCalls{}
|
||||
z := http.fetch(
|
||||
url: big_url
|
||||
user_ptr: progress_calls
|
||||
url: big_url
|
||||
user_ptr: progress_calls
|
||||
on_redirect: fn (req &http.Request, nredirects int, new_url string) ! {
|
||||
mut progress_calls := unsafe { &ProgressCalls(req.user_ptr) }
|
||||
eprintln('>>>>>>>> on_redirect, req.url: ${req.url} | new_url: ${new_url} | nredirects: ${nredirects}')
|
||||
|
@ -202,7 +202,7 @@ mut:
|
|||
fn (mut handler MyCountingHandler) handle(req http.Request) http.Response {
|
||||
handler.counter++
|
||||
mut r := http.Response{
|
||||
body: req.data + ', ${req.url}, counter: ${handler.counter}'
|
||||
body: req.data + ', ${req.url}, counter: ${handler.counter}'
|
||||
header: req.header
|
||||
}
|
||||
match req.url.all_before('?') {
|
||||
|
@ -224,10 +224,10 @@ fn test_my_counting_handler_on_random_port() {
|
|||
}
|
||||
mut server := &http.Server{
|
||||
show_startup_message: false
|
||||
addr: ''
|
||||
accept_timeout: atimeout
|
||||
handler: MyCountingHandler{}
|
||||
on_running: fn (mut server http.Server) {
|
||||
addr: ''
|
||||
accept_timeout: atimeout
|
||||
handler: MyCountingHandler{}
|
||||
on_running: fn (mut server http.Server) {
|
||||
spawn fn (mut server http.Server) {
|
||||
log.warn('server started')
|
||||
url := 'http://${server.addr}/count'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue