summaryrefslogtreecommitdiff
path: root/module/web/http.scm
AgeCommit message (Collapse)AuthorFilesLines
2024-12-22doc: srfi-19: Use `day' instead of `date' for `make-date'.Tomas Volf1-12/+12
Looking at the SRFI-19 specification, the argument is called `day', not `date'. Even the accessor is called `date-day'. So adjust the documentation to match. Also adjust the (web http) module, which was using `date' as well. * doc/ref/srfi-modules.texi (SRFI-19 Date): Use `day' instead of `date'. * module/web/http.scm (parse-rfc-822-date, parse-rfc-850-date) (parse-asctime-date): Same. Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2023-06-08Use custom binary output ports for make-chunked-output-portAndy Wingo1-25/+13
* module/web/http.scm (make-chunked-output-port): Use custom binary output ports.
2023-02-24Remove unnecessary module imports.Ludovic Courtès1-2/+0
These were found with: make GUILE_WARNINGS='-W1 -Wunused-module' * module/ice-9/copy-tree.scm: * module/ice-9/eval-string.scm: * module/ice-9/getopt-long.scm: * module/ice-9/poll.scm: * module/ice-9/popen.scm: * module/ice-9/sandbox.scm: * module/ice-9/threads.scm: * module/sxml/apply-templates.scm: * module/sxml/simple.scm: * module/system/base/types.scm: * module/system/repl/command.scm: * module/system/repl/common.scm: * module/system/repl/coop-server.scm: * module/system/repl/debug.scm: * module/system/repl/error-handling.scm: * module/system/repl/repl.scm: * module/system/repl/server.scm: * module/system/vm/assembler.scm: * module/system/vm/disassembler.scm: * module/system/vm/dwarf.scm: * module/system/vm/elf.scm: * module/system/vm/frame.scm: * module/system/vm/inspect.scm: * module/system/vm/linker.scm: * module/system/vm/program.scm: * module/system/vm/trace.scm: * module/system/vm/trap-state.scm: * module/system/vm/traps.scm: * module/system/xref.scm: * module/texinfo/indexing.scm: * module/texinfo/plain-text.scm: * module/texinfo/reflection.scm: * module/texinfo/string-utils.scm: * module/web/client.scm: * module/web/http.scm: * module/web/request.scm: * module/web/response.scm: Remove imports of unused modules.
2022-07-04web: Don't hide missing data in the chunked input port.Christopher Baines1-2/+16
This port is of limited use if it cannot be used reliably. Rather than behaving as if the input has finished when it ends unexpectedly, instead raise an exception. * module/web/http.scm (make-chunked-input-port): Raise an exception on premature termination. (&chunked-input-ended-prematurely): New exception type. (chunked-input-ended-prematurely-error?): New procedure. * test-suite/tests/web-http.test (pass-if-named-exception): Rename to pass-if-named-exception. (pass-if-named-exception): New syntax. ("Exception on premature chunk end"): New test for this behaviour. Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2022-07-04web: Handle ending CRLF (\r\n) for chunked input and output ports.Christopher Baines1-1/+2
The chunked transfer encoding specifies the chunked body ends with CRLF. This is in addition to the CRLF at the end of the last chunk, so there should be CRLF twice at the end of the chunked body: https://datatracker.ietf.org/doc/html/rfc2616#section-3.6.1 * module/web/http.scm (make-chunked-input-port): Read two extra bytes at the end of the chunked input. (make-chunked-output-port): Write the missing \r\n when closing the port. * test-suite/tests/web-http.test (chunked encoding): Add missing \r\n to test data. Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2022-07-04web: send capitalized authorization header schemeAleix Conchillo Flaqué1-2/+12
* module/web/http.scm (write-credentials): capitalize authorization header scheme. The standard allows the scheme to be case-insensitive, however most libraries out there expect the scheme to be capitalized, which is what it is actually used in RFC docs (e.g. https://datatracker.ietf.org/doc/html/rfc7617#section-2). Some libraries even reject lowercase scheme making Guile incompatible. Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2021-03-12Revert "Handle CRLF and Unicode line endings in read-line"Andy Wingo1-6/+8
This reverts commit 0f983e3db0c43ad7c89f57ea84f792ede373ba0c. 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.
2021-03-11Handle CRLF and Unicode line endings in read-lineMike Gran1-8/+6
* 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
2020-05-18http: Support CONNECT and PATCH HTTP methods.Christopher Baines1-0/+2
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>
2019-06-24Revert "web: Add support for HTTP header continuation lines."Mark H Weaver1-24/+7
Fixes <https://bugs.gnu.org/36350>. This reverts commit 73cde5ed7218a090ecee888870908af5445796f0.
2019-06-18web: Add support for HTTP header continuation lines.Mark H Weaver1-7/+24
* 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.
2017-11-11http: Fix typo in proxy handling in 'write-request-line'.Ludovic Courtès1-3/+3
Reported by Mark H Weaver <mhw@netris.org> at <https://lists.gnu.org/archive/html/guix-devel/2017-11/msg00190.html>. * module/web/http.scm (write-request-line): Fix more typos introduced in 96b994b6f815747ce2548123cc996d8132bd4781.
2017-11-10http: Fix typo in proxy handling in 'write-request-line'.Ludovic Courtès1-2/+2
Reported by Konrad Hinsen <konrad.hinsen@fastmail.net> at <https://lists.gnu.org/archive/html/guix-devel/2017-11/msg00070.html>. * module/web/http.scm (write-request-line): Move 'string-index' first in 'cond' clause. Fixes a regression introduced in 96b994b6f815747ce2548123cc996d8132bd4781.
2017-05-21web: add support for URI-referenceAndy Wingo1-39/+9
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.
2017-03-01http: Do not use 'eq?' to compare characters in parse-request-uri.Mark H Weaver1-1/+1
* module/web/http.scm (parse-request-uri): Use 'eqv?' to compare characters.
2017-02-08Remove remaining "display" uses in (web http)Andy Wingo1-59/+62
* 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.
2017-02-08Beginnings of suspendable HTTPAndy Wingo1-134/+146
* 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.
2017-02-08Modernize (web http) a bitAndy Wingo1-353/+356
* 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.
2016-08-28ETag list headers accept sloppy etagsAndy Wingo1-19/+33
* 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.
2016-05-22http: Accept date strings with a leading space for hours.Ludovic Courtès1-0/+20
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.
2016-05-22http: Use 'read-header-line' instead of 'read-line*'.Ludovic Courtès1-19/+3
* module/web/http.scm (read-line*): Remove. (read-continuation-line, read-header, read-request-line): Use 'read-header-line' instead of 'read-line*'.
2016-05-22http: Accept empty reason phrases.Ludovic Courtès1-5/+20
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.
2016-05-22web: Gracefully handle premature EOF when reading chunk header.Ludovic Courtès1-9/+16
* module/web/http.scm (read-chunk-header): Return 0 when 'read-line' returns EOF.
2016-05-22http: Do not buffer HTTP chunks.Ludovic Courtès1-34/+32
Fixes <http://bugs.gnu.org/19939>. * module/web/http.scm (read-chunk, read-chunk-body): Remove. (make-chunked-input-port)[next-chunk, buffer-, buffer-size, buffer-pointer]: Remove. [chunk-size, remaining]: New variables. [read!]: Rewrite to write directly to BV. * test-suite/tests/web-http.test ("chunked encoding")["reads chunks without buffering", "reads across chunk boundaries"]: New tests.
2016-04-11make-chunked-output-port buffering fixAndy Wingo1-7/+11
* 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.
2016-01-07web: Be less strict when parsing entity tags.Andy Wingo1-4/+9
* 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.
2014-11-01web: Location header is URI-reference; better URI-reference supportAndy Wingo1-27/+29
* 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.
2014-01-21Write out HTTP Basic auth headers correctly.Mark H Weaver1-4/+4
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.
2014-01-20Add support for content-dispositionAndy Wingo1-1/+25
* 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.
2013-11-19Web: accept "UTC" as the zone offset in date headers.Mark H Weaver1-0/+2
Fixes <http://bugs.gnu.org/14128>. Reported by Aleix Conchillo Flaqué <aconchillo@gmail.com>. * module/web/http.scm (parse-zone-offset): Accept "UTC".
2013-08-19`write-request-line' always prints a path component.Ian Price1-6/+3
* 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.
2013-07-16Add support for HTTP proxies.Mark H Weaver1-1/+24
* 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'.
2013-03-27web http: parse numeric time zones in headersDaniel Hartwig1-15/+46
* module/web/http.scm (parse-zone-offset, normalize-date): New procedures. (parse-rfc-822-date, parse-rfc-850-date, parse-date): Update. * test-suite/tests/web-http.test ("general headers"): Add test. Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2013-03-16http: support IP-literal (IPv6 address) in Host headerDaniel Hartwig1-6/+20
* 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.
2013-03-16minor tweaks to web documentationDaniel Hartwig1-3/+3
* 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.
2013-01-11remove (web http) TODO listAndy Wingo1-7/+0
* module/web/http.scm: Remove outdated TODO list.
2013-01-07http-get: don't shutdown write end of socketAndy Wingo1-3/+13
* 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.
2012-11-27web client: correctly handle uri-query, etc. in relative URI headersDaniel Hartwig1-9/+3
* 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.
2012-11-27web client: Support relative URIs in some headers.Ludovic Courtès1-2/+17
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>.
2012-11-24syncronize web module docstrings with manualDaniel Hartwig1-45/+42
* 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).
2012-07-06Document and export `declare-opaque-header!'Ian Price1-0/+3
* module/web/http.scm (declare-opaque-header!): Add docstring. New export. * doc/ref/web.texi (HTTP): Add documentation.
2012-07-06Add HTTP Chunked Encoding support to web modules.Ian Price1-1/+103
* doc/ref/web.texi(Transfer Codings): New subsection for transfer codings. * module/web/http.scm(make-chunked-input-port, make-chunked-output-port): New procedures. * module/web/response.scm (read-response-body): Handle chunked responses. * test-suite/tests/web-response.test: Add test. * test-suite/tests/web-http.test: Add tests. afd
2012-03-22add exception printers for bad-header, bad-header-componentAndy Wingo1-1/+16
* module/web/http.scm (bad-header-component): Throw 'bad-header-component instead of 'bad-header. (bad-header-printer, bad-header-component-printer): Add exception printers.
2012-03-22micro-optimizations to string-trim-both, and to (web http)Andy Wingo1-24/+20
* 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.
2012-03-12web http: fix Ma -> MarAndy Wingo1-2/+2
* module/web/http.scm (write-date): Fix serialization of Mar. Oops.
2012-02-02Improve the usage of variable names in Scheme docstrings.Bake Timmons1-1/+1
* 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.
2012-01-09permit non-date values for Expires headerDaniel Hartwig1-1/+9
* module/web/http.scm ("Expires"): Permit (some) non-date values.
2012-01-07`write-request-line' writes absolute paths, not absolute URIs.Ian Price1-1/+12
* module/web/http.scm (write-request-line): RFC 2616 says that absolute paths are used to identify resources on an origin server.
2012-01-07remove duplicate write-uri definitionAndy Wingo1-3/+0
* module/web/http.scm: Remove duplicate write-uri definition.
2011-12-22HTTP: Fix qstring writing of cache-extension valuesAndy Wingo1-1/+1
* 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.