guile-devel
[Top][All Lists]
Advanced

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

Re: [PATCH]: correctly call build-request


From: Ian Price
Subject: Re: [PATCH]: correctly call build-request
Date: Tue, 27 Aug 2013 16:12:59 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux)

Alexandru Cojocaru <address@hidden> writes:

> Hi,
> http-post currently sends a GET method instead of POST, I tracked down
> the problem
> to extend-request.
It would have been nice to send an example. It's a little annoying to
work backwards from a patch to a bug. :)

scheme@(guile-user)> (use-modules (web uri) (web client))
scheme@(guile-user)> (let ((out (open-output-string)))
                       (catch #t
                         (lambda ()
                           (http-post (string->uri "http://www.example.com";)
                                      #:port out
                                      #:body ""))
                         (lambda _
                           (get-output-string out))))
$15 = "GET / HTTP/1.1\r\nContent-Type: text/plain;charset=utf-8\r\nHost: 
www.example.com\r\nConnection: close\r\n\r\n"

>  (define (extend-request r k v . additional)
> -  (let ((r (build-request (request-uri r) #:version (request-version r)
> +  (let ((r (build-request (request-uri r)
> +                          #:method (request-method r)
> +                          #:version (request-version r)
>                            #:headers
>                            (assoc-set! (copy-tree (request-headers r))
>                                        k v)
> -                          #:port (request-port r))))
> +                          #:port (request-port r)
> +                          #:meta (request-meta r))))
Seems fine to me.

>      (if (null? additional)
>          r
>          (apply extend-request r additional))))
> @@ -125,7 +128,7 @@ as is the case by default with a request returned by 
> `build-request'."
>    (cond
>     ((not body)
>      (let ((length (request-content-length request)))
> -      (if length
> +      (when length
>            (unless (zero? length)
>              (error "content-length, but no body"))
>            (when (assq 'transfer-encoding (request-headers request))
You've merely switched the case around.

Previously, when length was #f, and transfer-encoding was asked for, you
got an error.

Now, when length is not #f, transfer encoding is asked for, and content
length is zero, you get an error.

The latter does not generalise the former.

The correct thing should be more like (untested)

(when (and length (not (zero? length)))
  (error "content-length, but no body"))
(when (assq 'transfer-encoding (request-headers request))
  (error "transfer-encoding not allowed with no body"))
(values request #vu8)

That said, why do we forbid transfer encoding? Pointless though it may
be, I don't think there is a technical or standards reason why it
shouldn't work.


-- 
Ian Price -- shift-reset.com

"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"



reply via email to

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