vweb: remove chunked encoding support in server responses (#10750)
parent
ee00d80931
commit
c3c420a41c
|
@ -40,7 +40,6 @@ pub fn (mut app App) index() vweb.Result {
|
||||||
show := true
|
show := true
|
||||||
hello := 'Hello world from vweb'
|
hello := 'Hello world from vweb'
|
||||||
numbers := [1, 2, 3]
|
numbers := [1, 2, 3]
|
||||||
app.enable_chunked_transfer(40)
|
|
||||||
return $vweb.html()
|
return $vweb.html()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -122,13 +122,6 @@ fn test_http_client_index() ? {
|
||||||
assert x.text == 'Welcome to VWeb'
|
assert x.text == 'Welcome to VWeb'
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_http_client_chunk_transfer() ? {
|
|
||||||
x := http.get('http://127.0.0.1:$sport/chunk') or { panic(err) }
|
|
||||||
assert_common_http_headers(x) ?
|
|
||||||
assert x.header.get(.transfer_encoding) ? == 'chunked'
|
|
||||||
assert x.text == 'Lorem ipsum dolor sit amet, consetetur sadipscing'
|
|
||||||
}
|
|
||||||
|
|
||||||
fn test_http_client_404() ? {
|
fn test_http_client_404() ? {
|
||||||
url_404_list := [
|
url_404_list := [
|
||||||
'http://127.0.0.1:$sport/zxcnbnm',
|
'http://127.0.0.1:$sport/zxcnbnm',
|
||||||
|
|
|
@ -64,11 +64,6 @@ pub fn (mut app App) html_page() vweb.Result {
|
||||||
return app.html('<h1>ok</h1>')
|
return app.html('<h1>ok</h1>')
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut app App) chunk() vweb.Result {
|
|
||||||
app.enable_chunked_transfer(20)
|
|
||||||
return app.html('Lorem ipsum dolor sit amet, consetetur sadipscing')
|
|
||||||
}
|
|
||||||
|
|
||||||
// the following serve custom routes
|
// the following serve custom routes
|
||||||
['/:user/settings']
|
['/:user/settings']
|
||||||
pub fn (mut app App) settings(username string) vweb.Result {
|
pub fn (mut app App) settings(username string) vweb.Result {
|
||||||
|
|
|
@ -84,8 +84,6 @@ pub mut:
|
||||||
done bool
|
done bool
|
||||||
page_gen_start i64
|
page_gen_start i64
|
||||||
form_error string
|
form_error string
|
||||||
chunked_transfer bool
|
|
||||||
max_chunk_len int = 20
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct FileData {
|
struct FileData {
|
||||||
|
@ -137,36 +135,11 @@ pub fn (mut ctx Context) send_response_to_client(mimetype string, res string) bo
|
||||||
sb.write_string('HTTP/1.1 $ctx.status')
|
sb.write_string('HTTP/1.1 $ctx.status')
|
||||||
sb.write_string('\r\nContent-Type: $mimetype')
|
sb.write_string('\r\nContent-Type: $mimetype')
|
||||||
sb.write_string('\r\nContent-Length: $res.len')
|
sb.write_string('\r\nContent-Length: $res.len')
|
||||||
if ctx.chunked_transfer {
|
|
||||||
sb.write_string('\r\nTransfer-Encoding: chunked')
|
|
||||||
}
|
|
||||||
sb.write_string(ctx.headers)
|
sb.write_string(ctx.headers)
|
||||||
sb.write_string('\r\n')
|
sb.write_string('\r\n')
|
||||||
sb.write_string(vweb.headers_close.str())
|
sb.write_string(vweb.headers_close.str())
|
||||||
sb.write_string('\r\n')
|
sb.write_string('\r\n')
|
||||||
if ctx.chunked_transfer {
|
|
||||||
mut i := 0
|
|
||||||
mut len := res.len
|
|
||||||
for {
|
|
||||||
if len <= 0 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
mut chunk := ''
|
|
||||||
if len > ctx.max_chunk_len {
|
|
||||||
chunk = res[i..i + ctx.max_chunk_len]
|
|
||||||
i += ctx.max_chunk_len
|
|
||||||
len -= ctx.max_chunk_len
|
|
||||||
} else {
|
|
||||||
chunk = res[i..]
|
|
||||||
len = 0
|
|
||||||
}
|
|
||||||
sb.write_string(chunk.len.hex())
|
|
||||||
sb.write_string('\r\n$chunk\r\n')
|
|
||||||
}
|
|
||||||
sb.write_string('0\r\n\r\n') // End of chunks
|
|
||||||
} else {
|
|
||||||
sb.write_string(res)
|
sb.write_string(res)
|
||||||
}
|
|
||||||
s := sb.str()
|
s := sb.str()
|
||||||
defer {
|
defer {
|
||||||
unsafe { s.free() }
|
unsafe { s.free() }
|
||||||
|
@ -233,12 +206,6 @@ pub fn (mut ctx Context) not_found() Result {
|
||||||
return Result{}
|
return Result{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enables chunk transfer with max_chunk_len per chunk
|
|
||||||
pub fn (mut ctx Context) enable_chunked_transfer(max_chunk_len int) {
|
|
||||||
ctx.chunked_transfer = true
|
|
||||||
ctx.max_chunk_len = max_chunk_len
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sets a cookie
|
// Sets a cookie
|
||||||
pub fn (mut ctx Context) set_cookie(cookie Cookie) {
|
pub fn (mut ctx Context) set_cookie(cookie Cookie) {
|
||||||
mut cookie_data := []string{}
|
mut cookie_data := []string{}
|
||||||
|
|
Loading…
Reference in New Issue