1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 11:50:28 +02:00
Commit graph

70 commits

Author SHA1 Message Date
Andy Wingo
bf4e8f911e Use custom binary output ports for make-chunked-output-port
* module/web/http.scm (make-chunked-output-port): Use custom binary
output ports.
2023-06-08 09:03:10 +02:00
Ludovic Courtès
e2ed33ef04
Remove unnecessary module imports.
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.
2023-02-24 16:49:00 +01:00
Christopher Baines
baa1424335 web: Don't hide missing data in the chunked input port.
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-04 11:22:13 +02:00
Christopher Baines
9a3353a993 web: Handle ending CRLF (\r\n) for chunked input and output ports.
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-04 11:22:11 +02:00
Aleix Conchillo Flaqué
a84d8f6473 web: send capitalized authorization header scheme
* 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>
2022-07-04 11:16:36 +02:00
Andy Wingo
e30ee90478 Revert "Handle CRLF and Unicode line endings in read-line"
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.
2021-03-12 22:08:16 +01:00
Mike Gran
0f983e3db0 Handle CRLF and Unicode line endings in read-line
* 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
2021-03-11 19:42:33 -08:00
Christopher Baines
ac5df66f1c http: Support CONNECT and PATCH HTTP methods.
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>
2020-05-18 09:44:00 +02:00
Mark H Weaver
e1225d013e Revert "web: Add support for HTTP header continuation lines."
Fixes <https://bugs.gnu.org/36350>.

This reverts commit 73cde5ed72.
2019-06-24 11:33:13 -04:00
Mark H Weaver
73cde5ed72 web: Add support for HTTP header continuation lines.
* 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.
2019-06-18 08:28:01 -04:00
Ludovic Courtès
6ad28ae3bc http: Fix typo in proxy handling in 'write-request-line'.
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
96b994b6f8.
2017-11-11 15:14:54 +01:00
Ludovic Courtès
7d0d9e2c25 http: Fix typo in proxy handling in 'write-request-line'.
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
96b994b6f8.
2017-11-10 22:54:49 +01:00
Andy Wingo
7095a536f3 web: add support for URI-reference
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-05-21 13:42:29 +02:00
Mark H Weaver
b56b944920 http: Do not use 'eq?' to compare characters in parse-request-uri.
* module/web/http.scm (parse-request-uri): Use 'eqv?' to compare
characters.
2017-03-01 19:50:37 +01:00
Andy Wingo
ecdff904cb Remove remaining "display" uses in (web http)
* 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-08 15:09:14 +01:00
Andy Wingo
96b994b6f8 Beginnings of suspendable HTTP
* 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-08 15:09:14 +01:00
Andy Wingo
8c50060ae9 Modernize (web http) a bit
* 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.
2017-02-08 15:09:14 +01:00
Andy Wingo
342bd8dfb3 ETag list headers accept sloppy etags
* 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-08-28 13:48:42 +02:00
Ludovic Courtès
b9f6e89a27 http: Accept date strings with a leading space for hours.
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-22 20:14:34 +02:00
Ludovic Courtès
66bc464542 http: Use 'read-header-line' instead of 'read-line*'.
* 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-22 20:02:37 +02:00
Ludovic Courtès
f53145d41c http: Accept empty reason phrases.
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-22 20:02:37 +02:00
Ludovic Courtès
0bcf5d78ec web: Gracefully handle premature EOF when reading chunk header.
* module/web/http.scm (read-chunk-header): Return 0 when 'read-line'
  returns EOF.
2016-05-22 19:49:33 +02:00
Ludovic Courtès
751a55e355 http: Do not buffer HTTP chunks.
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-05-22 18:43:28 +02:00
Andy Wingo
55fb8f4e7e make-chunked-output-port buffering fix
* 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-04-11 22:23:47 +02:00
Andy Wingo
6d7c09c8a9 web: Be less strict when parsing entity tags.
* 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.
2016-01-07 10:53:57 +01:00
Andy Wingo
18c44b29e4 web: Location header is URI-reference; better URI-reference support
* 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-11-01 15:36:56 +01:00
Mark H Weaver
d0d8c872af Write out HTTP Basic auth headers correctly.
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-21 16:11:04 -05:00
Andy Wingo
6f4cc6a31e Add support for content-disposition
* 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.
2014-01-20 19:03:58 -05:00
Mark H Weaver
8904b7a936 Web: accept "UTC" as the zone offset in date headers.
Fixes <http://bugs.gnu.org/14128>.
Reported by Aleix Conchillo Flaqué <aconchillo@gmail.com>.

* module/web/http.scm (parse-zone-offset): Accept "UTC".
2013-11-19 03:22:00 -05:00
Ian Price
20d28792b3 `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.
2013-08-19 10:43:02 +01:00
Mark H Weaver
23cf330c86 Add support for HTTP proxies.
* 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-07-16 19:33:32 -04:00
Daniel Hartwig
ffc8eca636 web http: parse numeric time zones in headers
* 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-27 18:09:49 +01:00
Daniel Hartwig
b1c46fd30a http: support IP-literal (IPv6 address) in Host header
* 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-16 19:53:07 +08:00
Daniel Hartwig
dc87126115 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.
2013-03-16 17:53:53 +08:00
Andy Wingo
67e5ab8ac6 remove (web http) TODO list
* module/web/http.scm: Remove outdated TODO list.
2013-01-11 15:15:42 +01:00
Andy Wingo
ed3e8b8e06 http-get: don't shutdown write end of socket
* 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.
2013-01-07 23:21:16 +01:00
Daniel Hartwig
4e81e9d9a3 web client: correctly handle uri-query, etc. in relative URI headers
* 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-27 22:41:33 +01:00
Ludovic Courtès
261af76005 web client: Support relative URIs in some headers.
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-27 00:10:24 +01:00
Daniel Hartwig
06883ae000 syncronize web module docstrings with manual
* 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-11-24 15:40:14 +01:00
Ian Price
64ead01db7 Document and export `declare-opaque-header!'
* module/web/http.scm (declare-opaque-header!): Add docstring. New export.
* doc/ref/web.texi (HTTP): Add documentation.
2012-07-06 22:18:13 +02:00
Ian Price
312e79f8d5 Add HTTP Chunked Encoding support to web modules.
* 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-07-06 22:18:12 +02:00
Andy Wingo
1be6c7d34d add exception printers for bad-header, bad-header-component
* 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-22 09:56:27 +01:00
Andy Wingo
47153f29b0 micro-optimizations to string-trim-both, and to (web http)
* 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-22 09:55:28 +01:00
Andy Wingo
89d45e8507 web http: fix Ma -> Mar
* module/web/http.scm (write-date): Fix serialization of Mar.  Oops.
2012-03-12 16:58:15 +01:00
Bake Timmons
91a214ebd9 Improve the usage of variable names in Scheme docstrings.
* 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-02-02 12:24:40 +01:00
Daniel Hartwig
0e947e1d14 permit non-date values for Expires header
* module/web/http.scm ("Expires"): Permit (some) non-date values.
2012-01-09 23:36:59 +01:00
Ian Price
ab66fb3cd1 `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.
2012-01-07 01:36:34 +01:00
Andy Wingo
eaaf94c4ec remove duplicate write-uri definition
* module/web/http.scm: Remove duplicate write-uri definition.
2012-01-07 01:26:00 +01:00
Andy Wingo
61fe8eafc2 HTTP: Fix qstring writing of cache-extension values
* 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.
2011-12-22 08:18:05 -05:00
Daniel Hartwig
321770b2a3 Extend handling of "Cache-Control" header.
* 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.
2011-12-22 08:00:57 -05:00