vweb: remove chunked encoding support in server responses (#10750)

pull/10787/head
Miccah 2021-07-13 07:47:16 -05:00 committed by GitHub
parent ee00d80931
commit c3c420a41c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 1 additions and 47 deletions

View File

@ -40,7 +40,6 @@ pub fn (mut app App) index() vweb.Result {
show := true
hello := 'Hello world from vweb'
numbers := [1, 2, 3]
app.enable_chunked_transfer(40)
return $vweb.html()
}

View File

@ -122,13 +122,6 @@ fn test_http_client_index() ? {
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() ? {
url_404_list := [
'http://127.0.0.1:$sport/zxcnbnm',

View File

@ -64,11 +64,6 @@ pub fn (mut app App) html_page() vweb.Result {
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
['/:user/settings']
pub fn (mut app App) settings(username string) vweb.Result {

View File

@ -84,8 +84,6 @@ pub mut:
done bool
page_gen_start i64
form_error string
chunked_transfer bool
max_chunk_len int = 20
}
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('\r\nContent-Type: $mimetype')
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('\r\n')
sb.write_string(vweb.headers_close.str())
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()
defer {
unsafe { s.free() }
@ -233,12 +206,6 @@ pub fn (mut ctx Context) not_found() 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
pub fn (mut ctx Context) set_cookie(cookie Cookie) {
mut cookie_data := []string{}