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

37 commits

Author SHA1 Message Date
Andy Wingo
e9c5a1719b Move copy-tree to (ice-9 copy-tree); deprecate main binding
* doc/ref/api-data.texi (List Constructors):
* doc/ref/api-utility.texi (Copying): Update docs to mention module.
* libguile.h: Remove trees.h inclusion.
* libguile/Makefile.am (libguile_@GUILE_EFFECTIVE_VERSION@_la_SOURCES):
  (DOT_X_FILES, DOT_DOC_FILES, modinclude_HEADERS): Remove trees.c,
  trees.h, and related files.
* libguile/init.c (scm_i_init_guile): Remove trees.h and the
  scm_init_trees call.
* libguile/trees.c:
* libguile/trees.h: Remove.
* module/Makefile.am (SOURCES): Add ice-9/copy-tree.scm.
* module/ice-9/copy-tree.scm: New file.
* module/ice-9/deprecated.scm (copy-tree*): Export as copy-tree,
  proxying to (ice-9 copy-tree).
* module/system/repl/common.scm:
* module/web/client.scm:
* test-suite/tests/elisp.test:
* test-suite/tests/srfi-1.test:
* module/oop/goops/save.scm: Use (ice-9 copy-tree).
* test-suite/Makefile.am (SCM_TESTS): Add copy-tree.test.
* test-suite/tests/copy-tree.test: New file; test pulled from
  eval.test.
* libguile/deprecated.h:
* libguile/deprecated.c (scm_copy_tree): Deprecate.
2020-09-10 21:57:21 +02:00
Ludovic Courtès
a5421d2bb6 web: 'http-get' & co. now honor #:verify-certificate?.
Previously they would always assume #:verify-certificate? #t,
unless #:port was given.

Fixes <https://bugs.gnu.org/40486>.
Reported by Jan Synacek <jsynacek@redhat.com>.

* module/web/client.scm (define-http-verb): Pass #:verify-certificate?
to 'open-socket-for-uri'.
2020-05-27 23:28:14 +02:00
Ludovic Courtès
076276c4f5 web: Client treats TLS "premature termination" error as EOF.
Fixes <https://bugs.gnu.org/39800>.
Reported by <franco.rcr@gmail.com>.

* module/web/client.scm (tls-wrap)[read!]: Catch 'gnutls-error around
'get-bytevector-some' call.
2020-03-06 23:04:12 +01:00
Ludovic Courtès
c3daf58b89 web: Update comment regarding the 'tls-wrap' port wrapper.
* module/web/client.scm (tls-wrap): Update comment.
2020-01-13 11:07:05 +01:00
Ludovic Courtès
38f14ce65d web: 'open-socket-for-uri' can verify the server's X.509 certificate.
This is largely based on Guix commit
bc3c41ce36349ed4ec758c70b48a7059e363043a and subsequent changes to that
code.

* module/web/client.scm (x509-certificate-directory): New variable.
(set-certificate-credentials-x509-trust-file!*)
(make-credendials-with-ca-trust-files, peer-certificate)
(assert-valid-server-certificate, print-tls-certificate-error): New
procedures.
<top level>: Add call to 'set-exception-printer!'.
(tls-wrap): Add #:verify-certificate? parameter.  When it is true, call
'make-credendials-with-ca-trust-files', pass it to
'set-session-credentials!', and call 'assert-valid-server-certificate'.
(open-socket-for-uri): Add #:verify-certificate? parameter and pass it
to 'tls-wrap'.
(http-request): Add #:verify-certificate? parameter and pass it to
'open-socket-for-uri'.
(define-http-verb): Add #:verify-certificate? parameter and pass it to
'http-request'.
* doc/ref/web.texi (Web Client): Update documentation of
'open-socket-for-uri' and 'http-request'.  Document
'x509-certificate-directory'.
2020-01-13 11:06:01 +01:00
Ludovic Courtès
bcba213284 web: Continue handshake upon TLS warning alerts.
This is a backport of Guix commit 7b9ac883ea62a816afbfa747c1377dc273c15c20.

* module/web/client.scm (tls-wrap): Catch 'gnutls-error' around
'handshake'.  Upon ERROR/WARNING-ALERT-RECEIVED, print a message and
call 'handshake'.
2020-01-13 11:06:01 +01:00
Ludovic Courtès
80bbebef4d web: Add 'current-https-proxy' and honor $https_proxy.
* module/web/client.scm (current-https-proxy): New variable.
(setup-http-tunnel): New procedure.
(open-socket-for-uri): Move 'http-proxy', 'uri', and 'addresses' inside
'open-socket'.  Remove 'with-https-proxy' macro.  Add call to
'setup-http-tunnel'.  Honor 'current-https-proxy' in 'open-socket'.
* doc/ref/web.texi (Web Client): Document 'current-https-proxy'.
* doc/ref/guile.texi: Update copyright years.

Based on Guix commit 9bc8175cfa6b23c31f6c43531377d266456e430e.

Co-authored-by: Sou Bunnbu (宋文武) <iyzsong@gmail.com>
2020-01-13 11:06:01 +01:00
Ludovic Courtès
c9b83a27c7 web: Adjust (gnutls) loading to new module autoload semantics.
Prior to commit cb14fd2143 (Guile 2.9.7),
autoloading a module would give you access to all its bindings.  In
future versions, autoloading a module gives access only to the listed
bindings, as per #:select (see <https://bugs.gnu.org/38895>).

This commit adjusts autoloads to the new semantics, fixing a regression
introduced in cb14fd2143.

* module/web/client.scm <top level>: Remove 'module-autoload!' call.
(gnutls-module, ensure-gnutls): Remove.
(load-gnutls): New procedure.
(tls-wrap): Call it instead of 'ensure-gnutls'.  Replace reference to
GNUTLS-MODULE by a call to 'resolve-interface'.
2020-01-13 11:06:01 +01:00
Arun Isaac
e40b5b54ff web: Export http-request.
* module/web/client.scm (request): Rename to http-request, add a
docstring, and export it.
(http-get, http-head, http-post, http-put, http-delete, http-trace,
http-options): Update docstring.
* doc/ref/web.texi (Web Client): Document http-request.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2018-08-07 12:13:19 +02:00
Andy Wingo
c248ea10be Remove all deprecated code
* module/ice-9/debug.scm:
* module/ice-9/mapping.scm:
* module/ice-9/syncase.scm: Delete these deprecated files.
* module/Makefile.am: Remove deleted files.
* libguile/deprecated.c:
* libguile/deprecated.h:
* libguile/backtrace.c:
* libguile/goops.c:
* libguile/numbers.c:
* libguile/socket.c:
* libguile/srfi-13.c:
* module/ice-9/deprecated.scm:
* module/ice-9/format.scm:
* module/oop/goops.scm:
* module/statprof.scm:
* module/texinfo/reflection.scm:
* module/web/client.scm:
* module/web/uri.scm: Remove deprecated code.
2017-05-22 13:36:42 +02: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
Andy Wingo
0c102b56e9 Fix reading of HTTPS responses that are smaller than port buffer
* module/web/client.scm (tls-wrap): Use get-bytevector-some instead of
  get-bytevector-n, to prevent Guile from attempting to read more bytes
  than are available.  Normally trying to read data on a shut-down
  socket is fine, but but gnutls issues an error if you attempt to read
  data from a shut-down socket, and that appears to be a security
  property.  Fixes HTTPS requests whose responses are smaller than the
  port buffer.
2017-04-28 13:38:41 +02:00
Ludovic Courtès
aa86fcb7d9 web: Avoid deprecated '_IOFBF'.
* module/web/client.scm (open-socket-for-uri): Use 'block instead of
_IOFBF.
2017-03-17 23:37:57 +01:00
Ludovic Courtès
011669af3b web: Remove export of nonexistent 'open-connection-for-uri'.
* module/web/client.scm: Don't export 'open-connection-for-uri', which
doesn't exist.
2017-03-17 23:35:24 +01:00
Christopher Allan Webber
8f1db9f268 web: Add https support through gnutls.
Since importing gnutls directly would result in a dependency cycle,
we load gnutls lazily.

This uses code originally written for Guix by Ludovic Courtès.

* module/web/client.scm: (%http-receive-buffer-size)
  (gnutls-module, ensure-gnutls, gnutls-ref, tls-wrap): New variables.
  (open-socket-for-uri): Wrap in tls when uri scheme is https.
* doc/ref/web.texi (open-socket-for-uri): Document gnutls usage.
2016-11-07 12:05:30 -06:00
Andy Wingo
59a18451b8 Use symbols instead of _IONBF values as args to setvbuf
* libguile/ports.c (scm_setvbuf): Use the symbols `none', `line', and
  `block' instead of the values `_IONBF', `_IOLBF', and `_IOFBF'.
* NEWS: Update.
* doc/ref/posix.texi (Ports and File Descriptors): Update setvbuf
documentation.
* module/ice-9/deprecated.scm (define-deprecated): New helper.
(_IONBF, _IOLBF, _IOFBF): Define deprecated values.
* benchmark-suite/benchmarks/read.bm ("read"):
* benchmark-suite/benchmarks/uniform-vector-read.bm
("uniform-vector-read!"):
* libguile/r6rs-ports.c (cbip_fill_input):
* module/system/base/types.scm (%ffi-memory-backend):
* module/web/client.scm (open-socket-for-uri):
* module/web/server/http.scm (http-read):
* test-suite/tests/ports.test ("pipe, fdopen, and line buffering"):
("setvbuf"):
* test-suite/tests/r6rs-ports.test ("7.2.7 Input Ports"): Update to use
non-deprecated interfaces.
2016-04-04 16:30:56 +02: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
Ludovic Courtès
0bb3f946e9 web: Keep the default size for the client's in-kernel receive buffer.
Fixes <http://bugs.gnu.org/15368>.

* module/web/client.scm (open-socket-for-uri): Remove call to
  'setsockopt'.  Contrary to what the comment said, its effect was to
  shrink the receive buffer from 124 KiB (the default size, per
  /proc/sys/net/core/rmem_default on Linux-based systems) to 12 KiB.
2014-05-23 22:02:30 +02:00
Mark H Weaver
76702cdcef Web: Use functional setters in extend-request and extend-response.
* module/web/client.scm (extend-request):
* module/web/server.scm (extend-response): Reimplement using
  functional setters.
2013-09-12 18:45:13 -04:00
Mark H Weaver
3b2226ec91 Web client+server: Add Content-Length header for empty bodies.
* module/web/client.scm (sanitize-request): Add a Content-Length
  header if a body if given, even if the body is empty.

* module/web/server.scm (sanitize-response): Add a Content-Length
  header if a body if given, even if the body is empty.
2013-09-12 18:36:45 -04:00
Mark H Weaver
55e29bb55b web client: HTTP methods are symbols, not strings.
* module/web/client.scm (request, http-get, http-head, http-post,
  http-put, http-delete, http-trace, http-options): HTTP methods are
  symbols.
2013-09-10 01:39:52 -04:00
Alexandru Cojocaru
9c85fd0221 Fix extend-request to preserve method and meta.
* module/web/client.scm (extend-request): Preserve method and meta.
2013-09-10 01:36:00 -04: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
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
170410b607 Fix http-get* deprecation note
* module/web/client.scm (http-get*): Fix deprecation warning.  Thanks to
  Daniel Hartwig for the report.
2013-01-21 22:13:30 +01:00
Andy Wingo
990b11c53f Add http-post, http-put, et cetera
* module/web/client.scm (ensure-uri): New helper.
  (open-socket-for-uri): Accept a URI as a string or as a URI object.
  (extend-request, sanitize-request): New helpers, like the
  corresponding functions in (web server).
  (decode-response-body): Add a reference to the HTTP/1.1 spec, and
  use (ice-9 iconv).
  (request): New helper, factoring all aspects of sending an HTTP
  request and getting a response.
  (http-get): Redefine in terms of http-get.  Deprecate the
  #:extra-headers argument in favor of #:headers.  Allow a body.  Add a
  #:streaming? argument, subsuming the functionality of http-get*.
  (http-get*): Deprecate.
  (http-head, http-post, http-put, http-delete, http-trace)
  (http-options): Define interfaces for all HTTP verbs.

* test-suite/tests/web-client.test: Add tests.

* doc/ref/web.texi: Update documentation.

Thanks to Gregory Benison for the initial patch.
2013-01-11 15:40:00 +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
Ludovic Courtès
b9d724982d web: Correctly detect "No route to host" conditions.
* module/web/client.scm (open-socket-for-uri): Delete addrinfos
  with the same address.  Always open SOCK_STREAM/IPPROTO_IP sockets.
  Fix the error handler's condition to determine what to do.
  Reported by Nikita Karetnikov <nikita.karetnikov@gmail.com> at
  <http://lists.gnu.org/archive/html/bug-guix/2012-12/msg00150.html>.
2012-12-17 00:27:00 +01:00
Ludovic Courtès
91e693a8e8 web: Add `http-get*'.
* module/web/client.scm (http-get*): New procedure.
* doc/ref/web.texi (Web Client): Document it.
2012-11-28 22:50:26 +01:00
Ludovic Courtès
ee2d874119 web: Export `text-content-type?'.
* module/web/client.scm (text-type?): Remove.
  (decode-response-body): Use `text-content-type?'.
* module/web/response.scm (text-content-type?): New procedure.
* doc/ref/web.texi (Responses): Document it.
2012-11-28 22:12:59 +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
Ludovic Courtès
f865ffaab1 web: Fix possible file descriptor leak in `open-socket-for-uri'.
* module/web/client.scm (open-socket-for-uri): Always close S in the
  `system-error' handler.
2012-10-13 21:13:10 +02:00
Ludovic Courtès
d74fcce9b9 web: Pass `AI_NUMERICSERV' when given a port number.
* module/web/client.scm (open-socket-for-uri)[addresses]: Pass
  AI_NUMERICSERV as the `getaddrinfo' hint when (uri-port URI) is true.
2012-10-12 23:21:39 +02:00
Ludovic Courtès
2663411bd7 web: Change `http-get' to try all the addresses for the given URI.
* module/web/client.scm (open-socket-for-uri): Try all the addresses
  returned by `getaddrinfo' until one succeeds.
2012-10-12 23:21:39 +02:00
Andy Wingo
fe0c202c0e Update a comment in (web client)
* module/web/client.scm: Update a comment.
2011-12-06 11:46:58 +01:00
Andy Wingo
072624134b open-socket-for-url returns port in latin1 encoding
* module/web/client.scm (open-socket-for-uri): Set port encoding to
  latin1, to see if this fixes Nalin Garut's problems.
2011-07-21 09:42:20 +02:00
Andy Wingo
680c8c5a99 add (web client)
* module/web/client.scm: New module, a simple synchronous web client.

* module/Makefile.am (WEB_SOURCES): Add to the build.
2011-07-15 13:36:47 +02:00