This reverts commit 0f983e3db0.
After discussing with Mike we are going to punt the read-line changes
for now. Open the port in O_TEXT mode if you want to chomp the CR in
CFLF sequences.
* libguile/rdelim.c (scm_read_line): handle CRLF, LS and PS
* module/ice-9/suspendable-ports.scm (read-line): handle CRLF, LS, and PS
* module/web/http.scm (read-header-line): take advantage of CRLF in read-line
(read-header): don't need to test for \return
* test-suite/tests/rdelim.test: new tests for read-line CRLF, LS and PS
* doc/ref/api-io.texi: update doc for read-line
PATCH is described by RFC 5789 and CONNECT is described by RFC 7231.
* module/web/http.scm (parse-http-method): Support CONNECT and PATCH.
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
* module/web/http.scm (spaces-and-tabs, space-or-tab?): New variables.
(read-header-line): After reading a header, if a space or tab follows,
read the continuation lines and join them.
* test-suite/tests/web-http.test: Add test.
Based on a patch by Daniel Hartwig <mandyke@gmail.com>.
* NEWS: Update.
* doc/ref/web.texi (URIs): Fragments are properly part of a URI, so
remove the incorrect note. Add documentation on URI subtypes.
* module/web/uri.scm (uri-reference?): New base type predicate.
(uri?, relative-ref?): Specific predicates.
(validate-uri-reference): Strict validation.
(validate-uri, validate-relative-ref): Specific validators.
(build-uri-reference, build-relative-ref): New constructors.
(string->uri-reference): Rename from string->uri.
(string->uri, string->relative-ref): Specific constructors.
(uri->string): Add #:include-fragment? keyword argument.
* module/web/http.scm (parse-request-uri): Use `build-uri-reference',
and result is a URI-reference, not URI, object. No longer infer an
absent `uri-scheme' is `http'.
(write-uri): Just use `uri->string'.
(declare-uri-header!): Remove unused function.
(declare-uri-reference-header!): Update. Rename from
`declare-relative-uri-header!'.
* test-suite/tests/web-uri.test ("build-uri-reference"):
("string->uri-reference"): Add.
("uri->string"): Also tests for relative-refs.
* test-suite/tests/web-http.test ("read-request-line"):
("write-request-line"): Update for no scheme in some URIs.
("entity headers", "request headers"): Content-location, Referer, and
Location should also parse relative-URIs.
* test-suite/tests/web-request.test ("example-1"): Expect URI-reference
with no scheme.
* module/web/http.scm (header-writer): Default to calling put-string.
(put-list): Rename from write-list, take the port first, and call the
put-item function with port then value. Adapt all callers.
(write-date): Rename display-digits to put-digits.
(put-challenge): Rename from write-challenge, adapt arguments to put
convention, and adapt callers.
(declare-symbol-list-header!): Use put-symbol.
(declare-integer-header!): Use put-non-negative-integer.o
(declare-entity-tag-list-header!): Use put-entity-tag-list.
("If-Range", "Etag"): Adapt to put-entity-tag.
(make-chunked-output-port): Use put-char.
* module/web/http.scm: Use put-string and other routines from (ice-9
textual-ports) in preference to `display'. The goal is for these
operations to be suspendable.
* module/web/http.scm: Modernize the Guile Scheme by using more match,
when, unless, and non-tail conversion. No functional change, with the
exception of fixing a bug in write-key-value-list for symbols like
100-continue that shouldn't print as #{100-continue}#.
* test-suite/tests/web-http.test (pass-if-only-parse):
(pass-if-reparse, pass-if-parse): Arrange to also serialize and
reparse values from pass-if-parse. Apply to all existing tests except
fragments where we don't expect fragments to be written out.
* module/web/http.scm (parse-entity-tag): Add #:sloppy-delimiters
keyword argument, and return a second value indicating the end
position.
(parse-entity-tag-list): Use parse-entity-tag, so that we also accept
sloppy etags that aren't qstrings.
* test-suite/tests/web-http.test ("request headers"): Add a test.
Fixes <http://bugs.gnu.org/23421>.
Reported by Ricardo Wurmus <ricardo.wurmus@mdc-berlin.de>.
* module/web/http.scm (parse-rfc-822-date): Add two clauses for hours
with a leading space.
* test-suite/tests/web-http.test ("general headers"): Add two tests.
Fixes <http://bugs.gnu.org/22273>.
Reported by Ricardo Wurmus <ricardo.wurmus@mdc-berlin.de>.
* module/web/http.scm (read-header-line): New procedure.
(read-response-line): Use it instead of 'read-line*'.
* test-suite/tests/web-http.test ("read-response-line"): Add test.
* module/web/http.scm (make-chunked-output-port): Add #:buffering
argument, defaulting to 1200 (some random value under the MTU). This
will force a flush every so often, and not every character as would
otherwise be the case after this port rewrite.
* module/web/http.scm (parse-entity-tag): Be less strict, accepting
unquoted strings as well.
* test-suite/tests/web-http.test ("response headers"): Add a test for
etag parsing.
* module/web/uri.scm (validate-uri): Add reference? keyword argument,
for validating references.
(build-uri): Clarify comments to indicate that the result is an
absolute URI.
(build-uri-reference): New interface, to build URI-references.
(string->uri-reference): Rename from string->uri*. Fix fragment
parsing to not include the #.
(string->uri): Adapt to string->uri-reference name change.
* module/web/request.scm (request-absolute-uri): Add default-scheme
optional argument. Use it if the request-uri has no scheme, or
error.
* module/web/http.scm (write-uri): Reflow to use "when". Fix writing of
URI-reference instances.
(declare-uri-reference-header!): Rename from
declare-relative-uri-header!. Use string->uri-reference.
("Location"): Declare as a URI-reference header, as per RFC 7231.
* module/web/client.scm (open-socket-for-uri): Handle the case in which
there is no URI scheme.
* test-suite/tests/web-http.test:
* test-suite/tests/web-uri.test: Add tests.
Fixes <http://bugs.gnu.org/14370>.
Reported by Atom X Zane <atomx@deadlyhead.com>.
* module/web/http.scm (write-credentials): Handle the Basic auth scheme
correctly.
* test-suite/tests/web-http.test (pass-if-round-trip): Use
'pass-if-equal' for better error reporting.
("request headers"): Add tests.
* THANKS: Add "Atom X Zane" to bug fix section.
* module/web/http.scm ("Content-Disposition"): Add a parser and
serializer. Defined in RFC2616 section 19.5.1.
* test-suite/tests/web-http.test ("entity headers"): New test case.
* module/web/http.scm (http-proxy-port?, set-http-proxy-port?!): New
exported procedures.
(write-request-line): If we're using an http proxy, write an
absolute-URI in the request line.
* module/web/client.scm: Import (web http).
(current-http-proxy): New exported parameter.
(open-socket-for-uri): If 'current-http-proxy' is not false,
connect to the proxy instead of the URI host, and use
'set-http-proxy-port?!' to make note of that fact.
* doc/ref/web.texi (Web Client): Document 'current-http-proxy'.
* module/web/http.scm ("Host"): Parse and write IP-literals treating
escapes as uri module does: remove brackets on parse, replace them on
write.
* test-suite/tests/web-http.test ("request headers"): Add tests.
* 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.
* module/web/http.scm ("Connection"): Write the "close" token in
lower-case.
* module/web/client.scm (http-get): Don't shutdown the writing side of
the pipe if we are not doing a keepalive, as this may prevent the
request from being sent at all. Prevented http://friendfeed.com/ from
being correctly fetched.
* module/web/uri.scm (uri-pat): Make scheme part optional.
(string->uri*): New private procedure to also parse relative URIs.
* module/web/http.scm (declare-relative-uri-header!): Use that.
Fixes <http://bugs.gnu.org/12827>.
* module/web/http.scm (declare-relative-uri-header!): New procedure.
("Content-Location", "Referer"): Use it.
Based on discussions with Daniel Hartwig <mandyke@gmail.com>.
* doc/ref/web.texi: Fix spacing. Update with a few missing function
descriptions.
* module/web/client.scm:
* module/web/http.scm:
* module/web/request.scm:
* module/web/server.scm:
* module/web/uri.scm: Update docstrings from manual (reworked by Ludovic
Courtès).
* libguile/srfi-13.c (scm_string_trim, scm_string_trim_right)
(scm_string_trim_both): Take the whitespace fast-path if the char_pred
is scm_char_set_whitespace.
* module/web/http.scm (read-header, split-and-trim, parse-quality-list):
(parse-param-component, parse-credentials, "Content-Type"):
(read-request-line, read-response-line): Use char-set:whitespace
instead of char-whitespace?. It avoids recursing into the VM.
* module/ice-9/boot-9.scm:
* module/ice-9/popen.scm:
* module/ice-9/pretty-print.scm:
* module/ice-9/r4rs.scm:
* module/rnrs/io/ports.scm:
* module/texinfo/string-utils.scm:
* module/web/http.scm:
* module/web/request.scm:
* module/web/response.scm:
* test-suite/vm/run-vm-tests.scm: Make the variable names in Scheme docstrings more
consistent. Replace a few instances of @var with @code when appropriate.
* module/web/http.scm ("Cache-Control"): Write string values using the
default val writer, to get quoting correct.
* test-suite/tests/web-http.test (pass-if-round-trip): New helper.
("general headers"): Check that cache-extensions round trip properly.
* module/web/http.scm ("Cache-Control"): Value for `max-stale' is
optional. Strict validation for value-less directives (`no-store',
etc.). String values optional for "cache-extension" directives.
* test-suite/tests/web-http.test: Value for `max-stale' is optional.
* module/web/http.scm (default-val-validator): Valid with no value.
(key-value-list?): Keys are always symbols, do not accept strings.
(validate-param-list): Apply `valid?' to list elements.
(validate-credentials): Validate param for Basic scheme, which
is parsed as a string.
(declare-symbol-list-header!): `list-of?' args were in wrong order.
("Cache-Control"): Replace `default-val-validator' with more
specific procedure.
("Accept"): Validate on first param which has no value.
* module/web/http.scm (parse-month, parse-rfc-822-date):
(parse-rfc-850-date, parse-asctime-date, parse-date):
(write-date): Parse and write dates without regard to the current
locale, using a custom parser. Also permits parsing of the deprecated
RFC 850 and asctime() date formats.