From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Roel Janssen Newsgroups: gmane.lisp.guile.user Subject: Re: Questions about the (web client) module. Date: Fri, 21 Jul 2017 00:36:13 +0200 Message-ID: <87h8y691nm.fsf@gnu.org> References: <87o9sfxtuk.fsf@gnu.org> <878tjjru96.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1500590216 21053 195.159.176.226 (20 Jul 2017 22:36:56 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 20 Jul 2017 22:36:56 +0000 (UTC) User-Agent: mu4e 0.9.18; emacs 25.1.1 Cc: guile-user@gnu.org To: Ludovic =?utf-8?Q?Court=C3=A8s?= Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Fri Jul 21 00:36:48 2017 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dYK3o-0004sz-Ol for guile-user@m.gmane.org; Fri, 21 Jul 2017 00:36:44 +0200 Original-Received: from localhost ([::1]:40249 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYK3u-0000OX-39 for guile-user@m.gmane.org; Thu, 20 Jul 2017 18:36:50 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47768) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYK3Z-0000OG-0z for guile-user@gnu.org; Thu, 20 Jul 2017 18:36:30 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYK3X-000745-W3 for guile-user@gnu.org; Thu, 20 Jul 2017 18:36:29 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:36506) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYK3S-00071h-Tn; Thu, 20 Jul 2017 18:36:22 -0400 Original-Received: from ip112-245-209-87.adsl2.static.versatel.nl ([87.209.245.112]:57947 helo=antelope) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1dYK3S-0008IG-Dm; Thu, 20 Jul 2017 18:36:22 -0400 In-reply-to: <878tjjru96.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.org gmane.lisp.guile.user:13957 Archived-At: Hi Ludo’, Thanks for your response. Ludovic Courtès writes: > Hi Roel, > > Roel Janssen 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. But 'Content-Type' and 'content-type' is not the same.. Adding a 'Content-Type' header results in the request having two 'Content-Type' headers. So it doesn't add 'Content-Type' when it isn't there, it converts 'content-type' to 'Content-Type', so it adds 'Content-Type' when 'content-type' isn't there. This seems wrong to me. > > 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. Or perhaps do not treat some HTTP headers different than others, and just keep it 'Content-Type' (as used in HTTP) instead of 'content-type'. > >> 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: The value I use is "guile-virtuoso-driver". All of the below functions work as expected with this value. Could it be that something else is wrong? Here's the entire code I use: --8<---------------cut here---------------start------------->8--- (define* (sparql-query-post query #:key (host "localhost") (port 8890) (graph "") (type "json")) (let ((base-uri (string-append "http://" host ":" (number->string port) )) (boundary "guile-virtuoso-driver")) (let ((body (string-append (format #f "--~a~%Content-Disposition: form-data; name=~s~%~%text/csv~%" boundary "format") (format #f "--~a~%Content-Disposition: form-data; name=~s~%~%~a~%--~a~%" boundary "query" query boundary)))) (http-post (string-append base-uri "/sparql") #:body body #:headers `((content-length . ,(string-length body)) (content-type . "multipart/form-data; boundary=guile-virtuoso-driver") (Accept . "*/*")))))) (define %query-get-all-triplets "SELECT * FROM WHERE { ?s ?p ?o }") (sparql-query-post %query-get-all-triplets) --8<---------------cut here---------------end--------------->8--- Which results in: --8<---------------cut here---------------start------------->8--- 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=guile-virtuoso-driver" --8<---------------cut here---------------end--------------->8--- Thanks! Kind regards, Roel Janssen