From c3c420a41c7ba78963db69f576dd39f93f9bbebe Mon Sep 17 00:00:00 2001 From: Miccah Date: Tue, 13 Jul 2021 07:47:16 -0500 Subject: [PATCH] vweb: remove chunked encoding support in server responses (#10750) --- examples/vweb/vweb_example.v | 1 - vlib/vweb/tests/vweb_test.v | 7 ------ vlib/vweb/tests/vweb_test_server.v | 5 ----- vlib/vweb/vweb.v | 35 +----------------------------- 4 files changed, 1 insertion(+), 47 deletions(-) diff --git a/examples/vweb/vweb_example.v b/examples/vweb/vweb_example.v index 40a242ecff..36db33cfdd 100644 --- a/examples/vweb/vweb_example.v +++ b/examples/vweb/vweb_example.v @@ -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() } diff --git a/vlib/vweb/tests/vweb_test.v b/vlib/vweb/tests/vweb_test.v index 83e5e7583f..2c4a52313f 100644 --- a/vlib/vweb/tests/vweb_test.v +++ b/vlib/vweb/tests/vweb_test.v @@ -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', diff --git a/vlib/vweb/tests/vweb_test_server.v b/vlib/vweb/tests/vweb_test_server.v index 68d8cb27fa..4dfeb7d3b4 100644 --- a/vlib/vweb/tests/vweb_test_server.v +++ b/vlib/vweb/tests/vweb_test_server.v @@ -64,11 +64,6 @@ pub fn (mut app App) html_page() vweb.Result { return app.html('

ok

') } -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 { diff --git a/vlib/vweb/vweb.v b/vlib/vweb/vweb.v index dbe4315a9a..3c3a0418a2 100644 --- a/vlib/vweb/vweb.v +++ b/vlib/vweb/vweb.v @@ -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{}