guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Questions about the (web client) module.


From: Ludovic Courtès
Subject: Re: Questions about the (web client) module.
Date: Thu, 20 Jul 2017 17:41:09 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux)

Hi Roel,

Roel Janssen <address@hidden> skribis:

> When I use http-post, and I want to change the HTTP header called
> "Content-Type", I seem to need to spell it as "content-type" in the
> #:headers part of the 'http-post' section.  Other headers like "Accept"
> do not seem to follow the same lowercase style route.
>
> More confusingly, using something like:
>   #:headers '((Content-Type . "text/csv"))
>
> leads to outputting the "Content-Type" header twice.
> Why is "content-type" special?

‘sanitize-request’ in (web client) adds a ‘Content-Type’ header if there
is none.

As for lower-case, perhaps the ‘request’ procedure in (web client)
should automatically convert to lower-case, or perhaps we should simply
clarify the documentation here.

> Then my next question is about "multipart/form-data" content types.
> My code looks like this:
>
>   #:headers `((content-type . ,(string-append
>                                 "multipart/form-data; boundary=" boundary))
>               (Accept . "*/*"))
>
> But that does not work:
>   scheme@(guile-user)> 
>   web/request.scm:184:10: In procedure build-request:
>   web/request.scm:184:10: Bad request: Bad value for header content-type: 
> "multipart/form-data; boundary=..."
>
> This is, however, a valid Content-Type.

What’s the value of ‘boundary’?  At first sight it looks good to me:

--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> ,use(web http)
scheme@(guile-user)> (valid-header? 'content-type (parse-header 'content-type 
"text/plain"))
$13 = #t
scheme@(guile-user)> (valid-header? 'content-type (parse-header 'content-type 
"multipart/form-data; boundary=2"))
$14 = #t
scheme@(guile-user)> (valid-header? 'content-type (parse-header 'content-type 
"multipart/form-data; boundary=sdfd"))
$15 = #t
scheme@(guile-user)> (parse-header 'content-type "multipart/form-data; 
boundary=sdfd")
$16 = (multipart/form-data (boundary . "sdfd"))
--8<---------------cut here---------------end--------------->8---

HTH!
Ludo’.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]