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

Allow extra http methods with form: PUT, PATCH

- Allow extra http methods with form: PUT, PATCH
- Rename `post_form` to `form`
This commit is contained in:
iRedMail 2019-08-10 15:12:17 +08:00 committed by Alexander Medvednikov
parent 1864e92ff4
commit 5a76255297

View File

@ -7,13 +7,17 @@ import (
http http
) )
const (
methods_with_form = ['POST', 'PUT', 'PATCH']
)
struct Context { struct Context {
static_files map[string]string static_files map[string]string
static_mime_types map[string]string static_mime_types map[string]string
pub: pub:
req http.Request req http.Request
conn net.Socket conn net.Socket
post_form map[string]string form map[string]string
// TODO Response // TODO Response
headers []string // response headers headers []string // response headers
} }
@ -136,12 +140,12 @@ pub fn run<T>(port int) {
app.vweb = Context{ app.vweb = Context{
req: req req: req
conn: conn conn: conn
post_form: map[string]string{} form: map[string]string{}
static_files: map[string]string{} static_files: map[string]string{}
static_mime_types: map[string]string{} static_mime_types: map[string]string{}
} }
//} //}
if req.method == 'POST' { if req.method in methods_with_form {
app.vweb.parse_form(s) app.vweb.parse_form(s)
} }
if vals.len < 2 { if vals.len < 2 {
@ -170,7 +174,7 @@ Content-Type: text/plain
fn (ctx mut Context) parse_form(s string) { fn (ctx mut Context) parse_form(s string) {
if ctx.req.method != 'POST' { if !(ctx.req.method in methods_with_form) {
return return
} }
pos := s.index('\r\n\r\n') pos := s.index('\r\n\r\n')
@ -185,7 +189,7 @@ fn (ctx mut Context) parse_form(s string) {
key := keyval[0] key := keyval[0]
val := http.unescape_url(keyval[1]) val := http.unescape_url(keyval[1])
println('http form "$key" => "$val"') println('http form "$key" => "$val"')
ctx.post_form[key] = val ctx.form[key] = val
} }
} }
} }