unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* Change to write-request-line
@ 2011-09-29 19:45 Ian Price
  2011-12-06 19:27 ` Andy Wingo
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Price @ 2011-09-29 19:45 UTC (permalink / raw)
  To: guile-devel

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


Hi guilers,

Two patches for the web stuff in guile. The first removes the second
definition of 'write-uri' from module/web/http.scm. No point having two
of them after all :-).

The second changes 'write-request-line' to write paths rather than full
uris. Quoth the RFC

   The most common form of Request-URI is that used to identify a
   resource on an origin server or gateway. In this case the absolute
   path of the URI MUST be transmitted (see section 3.2.1, abs_path) as
   the Request-URI, and the network location of the URI (authority) MUST
   be transmitted in a Host header field.

While the RFC also says that "The absoluteURI form is REQUIRED when the
request is being made to a proxy.", reading through the code for Ruby's
Net::HTTP and Haskell's Network.HTTP, they both seem to just use the
path and not provide for this situation, so I've held back on including
a #:absolute-uri? keyword to cover this.

Any thoughts on this?

-- 
Ian Price

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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: remove write-uri --]
[-- Type: text/x-patch, Size: 1793 bytes --]

From 90ee8b8eae09a6974959d43ce145f6565be10f90 Mon Sep 17 00:00:00 2001
From: Ian Price <ianprice90@googlemail.com>
Date: Thu, 29 Sep 2011 02:56:03 +0100
Subject: [PATCH 1/2] Remove second definition of `write-uri'

* module/web/http.scm (write-uri): remove procedure.
---
 module/web/http.scm |   28 ----------------------------
 1 files changed, 0 insertions(+), 28 deletions(-)

diff --git a/module/web/http.scm b/module/web/http.scm
index 70db813..f6aa5a0 100644
--- a/module/web/http.scm
+++ b/module/web/http.scm
@@ -1046,34 +1046,6 @@ three values: the method, the URI, and the version."
                 (parse-http-version line (1+ d1) (string-length line)))
         (bad-request "Bad Request-Line: ~s" line))))
 
-(define (write-uri uri port)
-  (if (uri-host uri)
-      (begin
-        (display (uri-scheme uri) port)
-        (display "://" port)
-        (if (uri-userinfo uri)
-            (begin
-              (display (uri-userinfo uri) port)
-              (display #\@ port)))
-        (display (uri-host uri) port)
-        (let ((p (uri-port uri)))
-          (if (and p (not (eqv? p 80)))
-              (begin
-                (display #\: port)
-                (display p port))))))
-  (let* ((path (uri-path uri))
-         (len (string-length path)))
-    (cond
-     ((and (> len 0) (not (eqv? (string-ref path 0) #\/)))
-      (bad-request "Non-absolute URI path: ~s" path))
-     ((and (zero? len) (not (uri-host uri)))
-      (bad-request "Empty path and no host for URI: ~s" uri))
-     (else
-      (display path port))))
-  (if (uri-query uri)
-      (begin
-        (display #\? port)
-        (display (uri-query uri) port))))
 
 (define (write-request-line method uri version port)
   "Write the first line of an HTTP request to @var{port}."
-- 
1.7.6.2


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: change write-request-line --]
[-- Type: text/x-patch, Size: 1030 bytes --]

From de698292c69e0073454107e5a1ff1f6c62d50b63 Mon Sep 17 00:00:00 2001
From: Ian Price <ianprice90@googlemail.com>
Date: Thu, 29 Sep 2011 03:12:00 +0100
Subject: [PATCH 2/2] `write-request-line' writes absolute paths, not absolute
 URIs.

* module/web/http.scm (write-request-line): RFC 2616 says that
  absolute paths are used to identify resources on an origin server.
---
 module/web/http.scm |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/module/web/http.scm b/module/web/http.scm
index f6aa5a0..1279acc 100644
--- a/module/web/http.scm
+++ b/module/web/http.scm
@@ -1051,7 +1051,10 @@ three values: the method, the URI, and the version."
   "Write the first line of an HTTP request to @var{port}."
   (display method port)
   (display #\space port)
-  (write-uri uri port)
+  (let ((path (uri-path uri)))
+    (if (string-null? path)
+        (display "/" port)
+        (display path port)))
   (display #\space port)
   (write-http-version version port)
   (display "\r\n" port))
-- 
1.7.6.2


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

* Re: Change to write-request-line
  2011-09-29 19:45 Change to write-request-line Ian Price
@ 2011-12-06 19:27 ` Andy Wingo
  2012-01-07  0:37   ` Andy Wingo
  0 siblings, 1 reply; 3+ messages in thread
From: Andy Wingo @ 2011-12-06 19:27 UTC (permalink / raw)
  To: Ian Price; +Cc: guile-devel

On Thu 29 Sep 2011 21:45, Ian Price <ianprice90@googlemail.com> writes:

> Two patches for the web stuff in guile. The first removes the second
> definition of 'write-uri' from module/web/http.scm. No point having two
> of them after all :-).

Probably better to remove the first one.  The second one allocates less,
catches some important error conditions, and doesn't write the fragment
component.

> The second changes 'write-request-line' to write paths rather than full
> uris. Quoth the RFC
>
>    The most common form of Request-URI is that used to identify a
>    resource on an origin server or gateway. In this case the absolute
>    path of the URI MUST be transmitted (see section 3.2.1, abs_path) as
>    the Request-URI, and the network location of the URI (authority) MUST
>    be transmitted in a Host header field.
>
> While the RFC also says that "The absoluteURI form is REQUIRED when the
> request is being made to a proxy.", reading through the code for Ruby's
> Net::HTTP and Haskell's Network.HTTP, they both seem to just use the
> path and not provide for this situation, so I've held back on including
> a #:absolute-uri? keyword to cover this.
>
> Any thoughts on this?

I guess that's OK.  Proxies probably DTRT already, and anyone who wants
something different should be able to write it fairly easily.

One thing though, you are missing the query component.  Care to post a
modifed patch?

Thanks, and sorry for the delay!

Andy
-- 
http://wingolog.org/



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

* Re: Change to write-request-line
  2011-12-06 19:27 ` Andy Wingo
@ 2012-01-07  0:37   ` Andy Wingo
  0 siblings, 0 replies; 3+ messages in thread
From: Andy Wingo @ 2012-01-07  0:37 UTC (permalink / raw)
  To: Ian Price; +Cc: guile-devel

On Tue 06 Dec 2011 20:27, Andy Wingo <wingo@pobox.com> writes:

> On Thu 29 Sep 2011 21:45, Ian Price <ianprice90@googlemail.com> writes:
>
>> Two patches for the web stuff in guile. The first removes the second
>> definition of 'write-uri' from module/web/http.scm. No point having two
>> of them after all :-).
>
> Probably better to remove the first one.  The second one allocates less,
> catches some important error conditions, and doesn't write the fragment
> component.

I pushed something like this.

>> The second changes 'write-request-line' to write paths rather than full
>> uris.
>
> One thing though, you are missing the query component.  Care to post a
> modifed patch?

I fixed it and pushed.

Thanks for the patches,

Andy
-- 
http://wingolog.org/



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

end of thread, other threads:[~2012-01-07  0:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-29 19:45 Change to write-request-line Ian Price
2011-12-06 19:27 ` Andy Wingo
2012-01-07  0:37   ` Andy Wingo

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).