guile-devel
[Top][All Lists]
Advanced

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

write-request-line empty path bug


From: Ian Price
Subject: write-request-line empty path bug
Date: Mon, 19 Aug 2013 03:45:14 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux)

Hi guys,

When you make a http request in guile where the URL has an empty path
and a non-empty query string, write-request-line fails to write the
/. This bit me just a few hours ago.

>From the RFC:

 If the abs_path is not present in the URL, it MUST be given as "/" when
 used as a Request-URI for a resource (section 5.1.2).

The code as written will not write it if a query is added, but this is
incorrect as far as the wording goes, because the query is not a part of
the abs_path.

This patch corrects this.

Hopefully it will mark the beginning of my glorious return to Guile
after some time apart :)

-- 
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"

>From 6cd6cbc1e77f159dcfabb2738877fc0022d8933c Mon Sep 17 00:00:00 2001
From: Ian Price <address@hidden>
Date: Mon, 19 Aug 2013 03:43:48 +0100
Subject: [PATCH] `write-request-line' always prints a path component.

* module/web/http.scm (write-request-line): Always write "/" when path
  is empty, regardless of query.
* test-suite/tests/web-http.test ("write-request-line"): Add test.
---
 module/web/http.scm            | 9 +++------
 test-suite/tests/web-http.test | 4 ++++
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/module/web/http.scm b/module/web/http.scm
index 21d2964..af04259 100644
--- a/module/web/http.scm
+++ b/module/web/http.scm
@@ -1137,16 +1137,13 @@ three values: the method, the URI, and the version."
           (display host-port port)))))
   (let ((path (uri-path uri))
         (query (uri-query uri)))
-    (if (not (string-null? path))
+    (if (string-null? path)
+        (display "/" port)
         (display path port))
     (if query
         (begin
           (display "?" port)
-          (display query port)))
-    (if (and (string-null? path)
-             (not query))
-        ;; Make sure we display something.
-        (display "/" port)))
+          (display query port))))
   (display #\space port)
   (write-http-version version port)
   (display "\r\n" port))
diff --git a/test-suite/tests/web-http.test b/test-suite/tests/web-http.test
index b2c5c2c..e24a268 100644
--- a/test-suite/tests/web-http.test
+++ b/test-suite/tests/web-http.test
@@ -173,6 +173,10 @@
                               (build-uri 'http
                                          #:path "/pub/WWW/TheProject.html")
                               (1 . 1))
+  (pass-if-write-request-line "GET /?foo HTTP/1.1"
+                              GET
+                              (build-uri 'http #:query "foo")
+                              (1 . 1))
   (pass-if-write-request-line "HEAD /etc/hosts?foo=bar HTTP/1.1"
                               HEAD
                               (build-uri 'http
-- 
1.7.11.7


reply via email to

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