From 1546090131f59ef8b5e2d00a8b805bbf55bb784e Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sat, 11 Sep 2021 04:21:10 +0300 Subject: [PATCH] vweb: remove a duplicate function parse_multipart_form --- vlib/net/http/request.v | 2 +- vlib/vweb/request.v | 36 ------------------------------------ vlib/vweb/vweb.v | 4 ++-- 3 files changed, 3 insertions(+), 39 deletions(-) diff --git a/vlib/net/http/request.v b/vlib/net/http/request.v index 41e22d917a..b94754c191 100644 --- a/vlib/net/http/request.v +++ b/vlib/net/http/request.v @@ -261,7 +261,7 @@ struct MultiplePathAttributesError { code int } -fn parse_multipart_form(body string, boundary string) (map[string]string, map[string][]FileData) { +pub fn parse_multipart_form(body string, boundary string) (map[string]string, map[string][]FileData) { sections := body.split(boundary) fields := sections[1..sections.len - 1] mut form := map[string]string{} diff --git a/vlib/vweb/request.v b/vlib/vweb/request.v index 836775fcbf..7c947f02ff 100644 --- a/vlib/vweb/request.v +++ b/vlib/vweb/request.v @@ -85,42 +85,6 @@ fn parse_form(body string) map[string]string { // ... } -fn parse_multipart_form(body string, boundary string) (map[string]string, map[string][]FileData) { - sections := body.split(boundary) - fields := sections[1..sections.len - 1] - mut form := map[string]string{} - mut files := map[string][]FileData{} - - for field in fields { - // TODO: do not split into lines; do same parsing for HTTP body - lines := field.split('\n')[1..] - disposition := parse_disposition(lines[0]) - // Grab everything between the double quotes - name := disposition['name'] or { continue } - // Parse files - // TODO: filename* - if 'filename' in disposition { - filename := disposition['filename'] - // Parse Content-Type header - if lines.len == 1 || !lines[1].to_lower().starts_with('content-type:') { - continue - } - mut ct := lines[1].split_nth(':', 2)[1] - ct = ct.trim_left(' \t').trim_right('\r') - data := lines_to_string(field.len, lines, 3, lines.len - 1) - files[name] << FileData{ - filename: filename - content_type: ct - data: data - } - continue - } - data := lines_to_string(field.len, lines, 2, lines.len - 1) - form[name] = data - } - return form, files -} - // Parse the Content-Disposition header of a multipart form // Returns a map of the key="value" pairs // Example: parse_disposition('Content-Disposition: form-data; name="a"; filename="b"') == {'name': 'a', 'filename': 'b'} diff --git a/vlib/vweb/vweb.v b/vlib/vweb/vweb.v index 18b20703fe..b919aa7172 100644 --- a/vlib/vweb/vweb.v +++ b/vlib/vweb/vweb.v @@ -141,7 +141,7 @@ pub mut: static_mime_types map[string]string form map[string]string query map[string]string - files map[string][]FileData + files map[string][]http.FileData header http.Header // response headers done bool page_gen_start i64 @@ -427,7 +427,7 @@ fn handle_conn(mut conn net.TcpConn, mut app T) { send_string(mut conn, vweb.http_400.bytestr()) or {} return } - form, files := parse_multipart_form(req.data, boundary[0][9..]) + form, files := http.parse_multipart_form(req.data, boundary[0][9..]) for k, v in form { app.form[k] = v }