1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

vweb: split and parse Content-Type header correctly (#9756)

This commit is contained in:
Miccah
2021-04-16 00:46:06 -05:00
committed by GitHub
parent b11b744630
commit e2be3ec396
5 changed files with 37 additions and 5 deletions

View File

@ -208,6 +208,31 @@ fn test_http_client_json_post() ? {
assert '$ouser' == '$nuser2'
}
fn test_http_client_multipart_form_data() ? {
boundary := '6844a625b1f0b299'
name := 'foo'
ct := 'multipart/form-data; boundary=------------------------$boundary'
contents := 'baz buzz'
data := '--------------------------$boundary
Content-Disposition: form-data; name=\"$name\"
$contents
--------------------------$boundary--
'
mut x := http.fetch('http://127.0.0.1:$sport/form_echo',
method: .post
header: http.new_header(
key: .content_type
value: ct
)
data: data
) ?
$if debug_net_socket_client ? {
eprintln('/form_echo endpoint response: $x')
}
assert x.text == contents
}
fn test_http_client_shutdown_does_not_work_without_a_cookie() {
x := http.get('http://127.0.0.1:$sport/shutdown') or {
assert err.msg == ''

View File

@ -85,6 +85,12 @@ pub fn (mut app App) json_echo() vweb.Result {
return app.ok(app.req.data)
}
['/form_echo'; post]
pub fn (mut app App) form_echo() vweb.Result {
app.set_content_type(app.req.header.get(.content_type) or { '' })
return app.ok(app.form['foo'])
}
// Make sure [post] works without the path
[post]
pub fn (mut app App) json() vweb.Result {