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

vweb: fix parsing of form fields, send with multipart/form-data (by JS fetch)

This commit is contained in:
Delyan Angelov
2023-07-14 16:07:52 +03:00
parent f1bc5e6d46
commit 9047f7c9a8
5 changed files with 72 additions and 24 deletions

View File

@ -238,6 +238,19 @@ fn test_http_client_multipart_form_data() {
assert x.body == files[0].data
}
fn test_login_with_multipart_form_data_send_by_fetch() {
mut form_config := http.PostMultipartFormConfig{
form: {
'username': 'myusername'
'password': 'mypassword123'
}
}
x := http.post_multipart_form('http://${localserver}/login', form_config)!
assert x.status_code == 200
assert x.status_msg == 'OK'
assert x.body == 'username: xmyusernamex | password: xmypassword123x'
}
fn test_host() {
mut req := http.Request{
url: 'http://${localserver}/with_host'

View File

@ -89,6 +89,11 @@ pub fn (mut app App) json_echo() vweb.Result {
return app.ok(app.req.data)
}
['/login'; post]
pub fn (mut app App) login_form(username string, password string) vweb.Result {
return app.html('username: x${username}x | password: x${password}x')
}
['/form_echo'; post]
pub fn (mut app App) form_echo() vweb.Result {
app.set_content_type(app.req.header.get(.content_type) or { '' })