diff options
| author | 2023-03-27 21:32:14 -0400 | |
|---|---|---|
| committer | 2023-03-27 21:32:14 -0400 | |
| commit | 155dad6563d3fb1afeadbecb3ed5760285e2db97 (patch) | |
| tree | dcf1262a2f958f8f18593a1a2ad0e4c54c294006 | |
| parent | janet: format using %V (diff) | |
janet: fix mime-related bug
tl;dr mimepost is at odds with post
so if we mimepost, do not change method
this means you cannot mimepost with a put
but that's probably fine
| -rw-r--r-- | jurl/init.janet | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/jurl/init.janet b/jurl/init.janet index a99ecd7..71c6188 100644 --- a/jurl/init.janet +++ b/jurl/init.janet @@ -155,9 +155,12 @@ (error "auth must either be a user:password string or [user:password [:valid :methods]]"))) + (var remethod true) (when body (match body (amime (= :jurl-mime (type amime) :amime)) - (pt :mimepost amime) + (do + (set remethod false) + (pt :mimepost amime)) (bytes (bytes? bytes)) (pt :postfields bytes) @@ -170,7 +173,9 @@ (pt :postfields (url-encoded dict)) (indx (indexed? indx)) - (pt :mimepost (mime/new handle ;indx)) + (do + (set remethod false) + (pt :mimepost (mime/new handle ;indx))) (error "body must either be a mime to do a multipart form submission, a buffer/string, callback function, a list of mime parts, or dictionary to url-encode"))) @@ -185,17 +190,18 @@ (indexed? headers) (pt :httpheader headers) (error "headers must be a dictionary or list"))) - (when method (case (text/keyword-lower method) - :get (pt :httpget true) - :post (pt :post true) - :put (pt :upload true) - :head (pt :nobody true) - :delete (pt :customrequest "DELETE") - :patch (pt :customrequest "PATCH") - :options (pt :customrequest "OPTIONS") - :connect (pt :customrequest "CONNECT") - :trace (pt :customrequest "TRACE") - (error "method must be one of :get :post :put :head :delete :patch :options :connect :trace"))) + (when (and method remethod) + (case (text/keyword-lower method) + :get (pt :httpget true) + :post (pt :post true) + :put (pt :upload true) + :head (pt :nobody true) + :delete (pt :customrequest "DELETE") + :patch (pt :customrequest "PATCH") + :options (pt :customrequest "OPTIONS") + :connect (pt :customrequest "CONNECT") + :trace (pt :customrequest "TRACE") + (error "method must be one of :get :post :put :head :delete :patch :options :connect :trace"))) (def res-body @"") (def res-hdr @"") |
