unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* [PATCH]: correctly call build-request
@ 2013-08-27 14:15 Alexandru Cojocaru
  2013-08-27 15:12 ` Ian Price
  2013-09-10  5:47 ` Mark H Weaver
  0 siblings, 2 replies; 4+ messages in thread
From: Alexandru Cojocaru @ 2013-08-27 14:15 UTC (permalink / raw)
  To: guile-devel

[-- Attachment #1: Type: text/plain, Size: 141 bytes --]

Hi,
http-post currently sends a GET method instead of POST, I tracked down 
the problem
to extend-request.

Best Regards,
Alexandru Cojocaru

[-- Attachment #2: client.patch --]
[-- Type: text/plain, Size: 1815 bytes --]

From 0d7fab577c878cad2c98d6b257e0a1bec84bc12e Mon Sep 17 00:00:00 2001
From: Alexandru Cojocaru <xojoc@gmx.com>
Date: Tue, 27 Aug 2013 15:59:39 +0200
Subject: [PATCH] fix call to build-request

* module/web/client.scm (extend-request): pass all the parameters to build-request

* module/web/client.scm (sanitize-request): don't allow transfer-coding
  to be set when content-length is 0
---
 module/web/client.scm |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
 mode change 100644 => 100755 module/web/client.scm

diff --git a/module/web/client.scm b/module/web/client.scm
old mode 100644
new mode 100755
index 7d5ea49..e7bccd1
--- a/module/web/client.scm
+++ b/module/web/client.scm
@@ -93,11 +93,14 @@
               (loop (cdr addresses))))))))
 
 (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))))
     (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))
-- 
1.7.9


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH]: correctly call build-request
  2013-08-27 14:15 [PATCH]: correctly call build-request Alexandru Cojocaru
@ 2013-08-27 15:12 ` Ian Price
  2013-08-27 16:00   ` Alexandru Cojocaru
  2013-09-10  5:47 ` Mark H Weaver
  1 sibling, 1 reply; 4+ messages in thread
From: Ian Price @ 2013-08-27 15:12 UTC (permalink / raw)
  To: Alexandru Cojocaru; +Cc: guile-devel

Alexandru Cojocaru <xojoc@gmx.com> 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"



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH]: correctly call build-request
  2013-08-27 15:12 ` Ian Price
@ 2013-08-27 16:00   ` Alexandru Cojocaru
  0 siblings, 0 replies; 4+ messages in thread
From: Alexandru Cojocaru @ 2013-08-27 16:00 UTC (permalink / raw)
  To: guile-devel

On 27.08.2013 17:12, Ian Price wrote:
> It would have been nice to send an example. It's a little annoying to
> work backwards from a patch to a bug. :)
I'll keep that in mind. But I said that the problem was with http-post 
so finding
an example shouldn't have been hard.
> You've merely switched the case around.
Ops.

Best regards,
Alexandru Cojocaru



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH]: correctly call build-request
  2013-08-27 14:15 [PATCH]: correctly call build-request Alexandru Cojocaru
  2013-08-27 15:12 ` Ian Price
@ 2013-09-10  5:47 ` Mark H Weaver
  1 sibling, 0 replies; 4+ messages in thread
From: Mark H Weaver @ 2013-09-10  5:47 UTC (permalink / raw)
  To: Alexandru Cojocaru; +Cc: guile-devel

Alexandru Cojocaru <xojoc@gmx.com> writes:
> http-post currently sends a GET method instead of POST, I tracked down
> the problem
> to extend-request.

I pushed the first hunk of your patch to stable-2.0.

    Thanks!
      Mark



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-09-10  5:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-27 14:15 [PATCH]: correctly call build-request Alexandru Cojocaru
2013-08-27 15:12 ` Ian Price
2013-08-27 16:00   ` Alexandru Cojocaru
2013-09-10  5:47 ` Mark H Weaver

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).