[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] GNU Guile branch, stable-2.0, updated. v2.0.7-201-g2e08f
From: |
Daniel Hartwig |
Subject: |
[Guile-commits] GNU Guile branch, stable-2.0, updated. v2.0.7-201-g2e08ff3 |
Date: |
Sat, 16 Mar 2013 09:58:32 +0000 |
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Guile".
http://git.savannah.gnu.org/cgit/guile.git/commit/?id=2e08ff38b735020e8ed5403acb637e6041d3d743
The branch, stable-2.0 has been updated
via 2e08ff38b735020e8ed5403acb637e6041d3d743 (commit)
via dc8712611597c6d5be918a69b0ce719e0675f6fe (commit)
from 01b83dbd1a11735519b7d6ca7b02006b45861c9c (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 2e08ff38b735020e8ed5403acb637e6041d3d743
Author: Daniel Hartwig <address@hidden>
Date: Sat Feb 23 15:15:33 2013 +0800
add tests for read-request-line, etc.
* test-suite/web/web-http.test ("read-request-line"):
("write-request-line", "read-response-line", "write-response-line"):
Add.
commit dc8712611597c6d5be918a69b0ce719e0675f6fe
Author: Daniel Hartwig <address@hidden>
Date: Sat Mar 16 17:53:53 2013 +0800
minor tweaks to web documentation
* doc/ref/web.texi: Say `World Wide Web'; the hyphenated form is almost
never used (c.f. w3.org).
General predicate arguments are named `obj'. Fill in arguments
omitted from some procedure definitions (e.g. `request-method').
Minor tweaks, such as using en-dash and missing markup as appropriate.
Wrap very long deffn lines.
* module/web/*.scm: Expand texinfo markup in doc strings. Synchronize
with changes in web.texi.
-----------------------------------------------------------------------
Summary of changes:
doc/ref/web.texi | 70 ++++++++++++++------------
module/web/client.scm | 6 +-
module/web/http.scm | 6 +-
module/web/response.scm | 6 +-
module/web/uri.scm | 28 +++++------
test-suite/tests/web-http.test | 107 ++++++++++++++++++++++++++++++++++++++++
6 files changed, 168 insertions(+), 55 deletions(-)
diff --git a/doc/ref/web.texi b/doc/ref/web.texi
index 70e0f2e..0d41f9f 100644
--- a/doc/ref/web.texi
+++ b/doc/ref/web.texi
@@ -10,7 +10,7 @@
@cindex HTTP
It has always been possible to connect computers together and share
-information between them, but the rise of the World-Wide Web over the
+information between them, but the rise of the World Wide Web over the
last couple of decades has made it much easier to do so. The result is
a richly connected network of computation, in which Guile forms a part.
@@ -206,9 +206,10 @@ The following procedures can be found in the @code{(web
uri)}
module. Load it into your Guile, using a form like the above, to have
access to them.
address@hidden {Scheme Procedure} build-uri scheme [#:address@hidden
[#:address@hidden @
- [#:address@hidden [#:address@hidden""}] [#:address@hidden @
- [#:address@hidden [#:address@hidden
address@hidden {Scheme Procedure} build-uri scheme @
+ [#:address@hidden [#:address@hidden [#:address@hidden @
+ [#:address@hidden""}] [#:address@hidden [#:address@hidden @
+ [#:address@hidden
Construct a URI object. @var{scheme} should be a symbol, @var{port}
either a positive, exact integer or @code{#f}, and the rest of the
fields are either strings or @code{#f}. If @var{validate?} is true,
@@ -216,7 +217,7 @@ also run some consistency checks to make sure that the
constructed URI
is valid.
@end deffn
address@hidden {Scheme Procedure} uri? x
address@hidden {Scheme Procedure} uri? obj
@deffnx {Scheme Procedure} uri-scheme uri
@deffnx {Scheme Procedure} uri-userinfo uri
@deffnx {Scheme Procedure} uri-host uri
@@ -249,9 +250,9 @@ Percent-decode the given @var{str}, according to
@var{encoding}, which
should be the name of a character encoding.
Note that this function should not generally be applied to a full URI
-string. For paths, use split-and-decode-uri-path instead. For query
-strings, split the query on @code{&} and @code{=} boundaries, and decode
-the components separately.
+string. For paths, use @code{split-and-decode-uri-path} instead. For
+query strings, split the query on @code{&} and @code{=} boundaries, and
+decode the components separately.
Note also that percent-encoded strings encode @emph{bytes}, not
characters. There is no guarantee that a given byte sequence is a valid
@@ -378,7 +379,8 @@ For more on the set of headers that Guile knows about out
of the box,
@pxref{HTTP Headers}. To add your own, use the @code{declare-header!}
procedure:
address@hidden {Scheme Procedure} declare-header! name parser validator writer
[#:address@hidden
address@hidden {Scheme Procedure} declare-header! name parser validator writer @
+ [#:address@hidden
Declare a parser, validator, and writer for a given header.
@end deffn
@@ -450,7 +452,7 @@ like @code{GET}.
@end deffn
@deffn {Scheme Procedure} parse-http-version str [start] [end]
-Parse an HTTP version from @var{str}, returning it as a major-minor
+Parse an HTTP version from @var{str}, returning it as a major--minor
pair. For example, @code{HTTP/1.1} parses as the pair of integers,
@code{(1 . 1)}.
@end deffn
@@ -471,7 +473,7 @@ Write the first line of an HTTP request to @var{port}.
@deffn {Scheme Procedure} read-response-line port
Read the first line of an HTTP response from @var{port}, returning three
-values: the HTTP version, the response code, and the "reason phrase".
+values: the HTTP version, the response code, and the ``reason phrase''.
@end deffn
@deffn {Scheme Procedure} write-response-line version code reason-phrase port
@@ -1130,13 +1132,13 @@ any loss of generality.
@subsubsection Request API
address@hidden {Scheme Procedure} request?
address@hidden {Scheme Procedure} request-method
address@hidden {Scheme Procedure} request-uri
address@hidden {Scheme Procedure} request-version
address@hidden {Scheme Procedure} request-headers
address@hidden {Scheme Procedure} request-meta
address@hidden {Scheme Procedure} request-port
address@hidden {Scheme Procedure} request? obj
address@hidden {Scheme Procedure} request-method request
address@hidden {Scheme Procedure} request-uri request
address@hidden {Scheme Procedure} request-version request
address@hidden {Scheme Procedure} request-headers request
address@hidden {Scheme Procedure} request-meta request
address@hidden {Scheme Procedure} request-port request
A predicate and field accessors for the request type. The fields are as
follows:
@table @code
@@ -1170,7 +1172,9 @@ request, you may read the body separately, and likewise
for writing
requests.
@end deffn
address@hidden {Scheme Procedure} build-request uri [#:method='GET]
[#:version='(1 . 1)] [#:headers='()] [#:port=#f] [#:meta='()]
[#:validate-headers?=#t]
address@hidden {Scheme Procedure} build-request uri [#:method='GET] @
+ [#:version='(1 . 1)] [#:headers='()] [#:port=#f] [#:meta='()] @
+ [#:validate-headers?=#t]
Construct an HTTP request object. If @var{validate-headers?} is true,
the headers are each run through their respective validators.
@end deffn
@@ -1253,12 +1257,12 @@ A helper routine to determine the absolute URI of a
request, using the
As with requests (@pxref{Requests}), Guile offers a data type for HTTP
responses. Again, the body is represented separately from the request.
address@hidden {Scheme Procedure} response?
address@hidden {Scheme Procedure} response-version
address@hidden {Scheme Procedure} response-code
address@hidden {Scheme Procedure} response? obj
address@hidden {Scheme Procedure} response-version response
address@hidden {Scheme Procedure} response-code response
@deffnx {Scheme Procedure} response-reason-phrase response
address@hidden {Scheme Procedure} response-headers
address@hidden {Scheme Procedure} response-port
address@hidden {Scheme Procedure} response-headers response
address@hidden {Scheme Procedure} response-port response
A predicate and field accessors for the response type. The fields are as
follows:
@table @code
@@ -1384,6 +1388,10 @@ Return @code{#t} if @var{type}, a symbol as returned by
@code{(web client)} provides a simple, synchronous HTTP client, built on
the lower-level HTTP, request, and response modules.
address@hidden
+(use-modules (web client))
address@hidden example
+
@deffn {Scheme Procedure} open-socket-for-uri uri
Return an open input/output port for a connection to URI.
@end deffn
@@ -1419,9 +1427,9 @@ If you already have a port open, pass it as @var{port}.
Otherwise, a
connection will be opened to the server corresponding to @var{uri}. Any
extra headers in the alist @var{headers} will be added to the request.
-If @var{body} is not #f, a message body will also be sent with the HTTP
-request. If @var{body} is a string, it is encoded according to the
-content-type in @var{headers}, defaulting to UTF-8. Otherwise
+If @var{body} is not @code{#f}, a message body will also be sent with
+the HTTP request. If @var{body} is a string, it is encoded according to
+the content-type in @var{headers}, defaulting to UTF-8. Otherwise
@var{body} should be a bytevector, or @code{#f} for no body. Although a
message body may be sent with any request, usually only @code{POST} and
@code{PUT} requests have bodies.
@@ -1480,8 +1488,8 @@ The life cycle of a server goes as follows:
@enumerate
@item
-The @code{open} hook is called, to open the server. @code{open} takes 0 or
-more arguments, depending on the backend, and returns an opaque
+The @code{open} hook is called, to open the server. @code{open} takes
+zero or more arguments, depending on the backend, and returns an opaque
server socket object, or signals an error.
@item
@@ -1578,8 +1586,8 @@ in, allowing the user's handler to explicitly manage its
state.
@end deffn
@deffn {Scheme Procedure} sanitize-response request response body
-"Sanitize" the given response and body, making them appropriate for the
-given request.
+``Sanitize'' the given response and body, making them appropriate for
+the given request.
As a convenience to web handler authors, @var{response} may be given as
an alist of headers, in which case it is used to construct a default
diff --git a/module/web/client.scm b/module/web/client.scm
index 9fbb25b..7d5ea49 100644
--- a/module/web/client.scm
+++ b/module/web/client.scm
@@ -248,10 +248,10 @@ pass it as PORT. The port will be closed at the end of
the
request unless KEEP-ALIVE? is true. Any extra headers in the
alist HEADERS will be added to the request.
-If BODY is not #f, a message body will also be sent with the HTTP
+If BODY is not â#fâ, a message body will also be sent with the HTTP
request. If BODY is a string, it is encoded according to the
content-type in HEADERS, defaulting to UTF-8. Otherwise BODY should be
-a bytevector, or #f for no body. Although it's allowed to send a
+a bytevector, or â#fâ for no body. Although it's allowed to send a
message body along with any request, usually only POST and PUT requests
have bodies. See âhttp-putâ and âhttp-postâ documentation, for more.
@@ -317,7 +317,7 @@ This function is similar to âhttp-getâ, except it uses
the \"HEAD\"
method. See âhttp-getâ for full documentation on the various keyword
arguments that are accepted by this function.
-Returns two values: the resulting response, and #f. Responses to HEAD
+Returns two values: the resulting response, and â#fâ. Responses to HEAD
requests do not have a body. The second value is only returned so that
other procedures can treat all of the http-foo verbs identically.")
diff --git a/module/web/http.scm b/module/web/http.scm
index c79d57d..712208b 100644
--- a/module/web/http.scm
+++ b/module/web/http.scm
@@ -167,7 +167,7 @@ The default writer is âdisplayâ."
(define *eof* (call-with-input-string "" read))
(define (read-header port)
- "Reads one HTTP header from PORT. Returns two values: the header
+ "Read one HTTP header from PORT. Return two values: the header
name and the parsed Scheme value. May raise an exception if the header
was known but the value was invalid.
@@ -220,7 +220,7 @@ as an ordered alist."
(define (write-headers headers port)
"Write the given header alist to PORT. Doesn't write the final
address@hidden, as the user might want to add another header."
+â\\r\\nâ, as the user might want to add another header."
(let lp ((headers headers))
(if (pair? headers)
(begin
@@ -971,7 +971,7 @@ as an ordered alist."
(define *known-versions* '())
(define* (parse-http-version str #:optional (start 0) (end (string-length
str)))
- "Parse an HTTP version from STR, returning it as a major-minor
+ "Parse an HTTP version from STR, returning it as a majorâminor
pair. For example, âHTTP/1.1â parses as the pair of integers,
â(1 . 1)â."
(or (let lp ((known *known-versions*))
diff --git a/module/web/response.scm b/module/web/response.scm
index 3f97dff..570a2d7 100644
--- a/module/web/response.scm
+++ b/module/web/response.scm
@@ -267,10 +267,10 @@ closes PORT, unless KEEP-ALIVE? is true."
(define* (response-body-port r #:key (decode? #t) (keep-alive? #t))
"Return an input port from which the body of R can be read. The
encoding of the returned port is set according to R's âcontent-typeâ
-header, when it's textual, except if DECODE? is #f. Return #f when no
-body is available.
+header, when it's textual, except if DECODE? is â#fâ. Return #f when
+no body is available.
-When KEEP-ALIVE? is #f, closing the returned port also closes R's
+When KEEP-ALIVE? is â#fâ, closing the returned port also closes R's
response port."
(define port
(cond
diff --git a/module/web/uri.scm b/module/web/uri.scm
index 25406b3..7fe0100 100644
--- a/module/web/uri.scm
+++ b/module/web/uri.scm
@@ -53,8 +53,8 @@
(query uri-query)
(fragment uri-fragment))
-(define (absolute-uri? x)
- (and (uri? x) (uri-scheme x) #t))
+(define (absolute-uri? obj)
+ (and (uri? obj) (uri-scheme obj) #t))
(define (uri-error message . args)
(throw 'uri-error message args))
@@ -309,17 +309,16 @@ serialization."
which should be the name of a character encoding.
Note that this function should not generally be applied to a full URI
-string. For paths, use split-and-decode-uri-path instead. For query
+string. For paths, use âsplit-and-decode-uri-pathâ instead. For query
strings, split the query on â&â and â=â boundaries, and decode
the components separately.
-Note also that percent-encoded strings encode @emph{bytes}, not
-characters. There is no guarantee that a given byte sequence is a valid
-string encoding. Therefore this routine may signal an error if the
-decoded bytes are not valid for the given encoding. Pass â#fâ for
-ENCODING if you want decoded bytes as a bytevector directly.
address@hidden, âset-port-encoding!â}, for more information on
-character encodings.
+Note also that percent-encoded strings encode _bytes_, not characters.
+There is no guarantee that a given byte sequence is a valid string
+encoding. Therefore this routine may signal an error if the decoded
+bytes are not valid for the given encoding. Pass â#fâ for ENCODING if
+you want decoded bytes as a bytevector directly. âset-port-encoding!â,
+for more information on character encodings.
Returns a string of the decoded characters, or a bytevector if
ENCODING was â#fâ."
@@ -380,11 +379,10 @@ ENCODING was â#fâ."
UNESCAPED-CHARS.
The default character set includes alphanumerics from ASCII, as well as
-the special characters @samp{-}, @samp{.}, @samp{_}, and @samp{~}. Any
-other character will be percent-encoded, by writing out the character to
-a bytevector within the given ENCODING, then encoding each byte as
-â%HHâ, where HH is the hexadecimal representation of
-the byte."
+the special characters â-â, â.â, â_â, and â~â. Any other
character will
+be percent-encoded, by writing out the character to a bytevector within
+the given ENCODING, then encoding each byte as â%HHâ, where HH is the
+hexadecimal representation of the byte."
(define (needs-escaped? ch)
(not (char-set-contains? unescaped-chars ch)))
(if (string-index str needs-escaped?)
diff --git a/test-suite/tests/web-http.test b/test-suite/tests/web-http.test
index 97f5559..6fa16bd 100644
--- a/test-suite/tests/web-http.test
+++ b/test-suite/tests/web-http.test
@@ -85,6 +85,113 @@
#t
(error "unexpected exception" component arg))))))))
+(define-syntax pass-if-read-request-line
+ (syntax-rules ()
+ ((_ str expected-method expected-uri expected-version)
+ (pass-if str
+ (equal? (call-with-values
+ (lambda ()
+ (read-request-line (open-input-string
+ (string-append str "\r\n"))))
+ list)
+ (list 'expected-method
+ expected-uri
+ 'expected-version))))))
+
+(define-syntax pass-if-write-request-line
+ (syntax-rules ()
+ ((_ expected-str method uri version)
+ (pass-if expected-str
+ (equal? (string-append expected-str "\r\n")
+ (call-with-output-string
+ (lambda (port)
+ (write-request-line 'method uri 'version port))))))))
+
+(define-syntax pass-if-read-response-line
+ (syntax-rules ()
+ ((_ str expected-version expected-code expected-phrase)
+ (pass-if str
+ (equal? (call-with-values
+ (lambda ()
+ (read-response-line (open-input-string
+ (string-append str "\r\n"))))
+ list)
+ (list 'expected-version
+ expected-code
+ expected-phrase))))))
+
+(define-syntax pass-if-write-response-line
+ (syntax-rules ()
+ ((_ expected-str version code phrase)
+ (pass-if expected-str
+ (equal? (string-append expected-str "\r\n")
+ (call-with-output-string
+ (lambda (port)
+ (write-response-line 'version code phrase port))))))))
+
+(with-test-prefix "read-request-line"
+ (pass-if-read-request-line "GET / HTTP/1.1"
+ GET
+ (build-uri 'http
+ #:path "/")
+ (1 . 1))
+ (pass-if-read-request-line "GET http://www.w3.org/pub/WWW/TheProject.html
HTTP/1.1"
+ GET
+ (build-uri 'http
+ #:host "www.w3.org"
+ #:path "/pub/WWW/TheProject.html")
+ (1 . 1))
+ (pass-if-read-request-line "GET /pub/WWW/TheProject.html HTTP/1.1"
+ GET
+ (build-uri 'http
+ #:path "/pub/WWW/TheProject.html")
+ (1 . 1))
+ (pass-if-read-request-line "HEAD /etc/hosts?foo=bar HTTP/1.1"
+ HEAD
+ (build-uri 'http
+ #:path "/etc/hosts"
+ #:query "foo=bar")
+ (1 . 1)))
+
+(with-test-prefix "write-request-line"
+ (pass-if-write-request-line "GET / HTTP/1.1"
+ GET
+ (build-uri 'http
+ #:path "/")
+ (1 . 1))
+ ;;; FIXME: Test fails due to scheme, host always being removed.
+ ;;; However, it should be supported to request these be present, and
+ ;;; that is possible with absolute/relative URI support.
+ ;; (pass-if-write-request-line "GET
http://www.w3.org/pub/WWW/TheProject.html HTTP/1.1"
+ ;; GET
+ ;; (build-uri 'http
+ ;; #:host "www.w3.org"
+ ;; #:path "/pub/WWW/TheProject.html")
+ ;; (1 . 1))
+ (pass-if-write-request-line "GET /pub/WWW/TheProject.html HTTP/1.1"
+ GET
+ (build-uri 'http
+ #:path "/pub/WWW/TheProject.html")
+ (1 . 1))
+ (pass-if-write-request-line "HEAD /etc/hosts?foo=bar HTTP/1.1"
+ HEAD
+ (build-uri 'http
+ #:path "/etc/hosts"
+ #:query "foo=bar")
+ (1 . 1)))
+
+(with-test-prefix "read-response-line"
+ (pass-if-read-response-line "HTTP/1.0 404 Not Found"
+ (1 . 0) 404 "Not Found")
+ (pass-if-read-response-line "HTTP/1.1 200 OK"
+ (1 . 1) 200 "OK"))
+
+(with-test-prefix "write-response-line"
+ (pass-if-write-response-line "HTTP/1.0 404 Not Found"
+ (1 . 0) 404 "Not Found")
+ (pass-if-write-response-line "HTTP/1.1 200 OK"
+ (1 . 1) 200 "OK"))
+
(with-test-prefix "general headers"
(pass-if-parse cache-control "no-transform" '(no-transform))
hooks/post-receive
--
GNU Guile
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Guile-commits] GNU Guile branch, stable-2.0, updated. v2.0.7-201-g2e08ff3,
Daniel Hartwig <=