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

170 commits

Author SHA1 Message Date
Andy Wingo
679eea4f0e allow URIs of the form file:///etc/hosts
* module/web/uri.scm (parse-authority): Allow empty authorities, so that
  we accept URIs of the form, file:///etc/hosts.
* test-suite/tests/web-uri.test ("string->uri"): Add tests.
2011-12-06 11:47:41 +01: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
Daniel Hartwig
69b8c5df14 fix validators for various list-style headers
* 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.
2011-11-23 23:35:20 +01:00
Andy Wingo
a24885b27d fix (web http) write-date for mondays
* module/web/http.scm (write-date): Fix bug on Mondays.  Jeez!
2011-10-17 09:52:04 +02:00
Ian Price
cb7bcfca35 RFC 822 allows single digit days of the month
* module/web/http.scm (parse-rfc-822-date): Add single digit day
  conditional.
* test-suite/tests/web-http.test("general headers"): Add test.
2011-09-10 11:12:04 -07:00
Andy Wingo
0c65f52c6d more define-syntax-rule usage
* module/ice-9/boot-9.scm:
* module/ice-9/control.scm:
* module/ice-9/futures.scm:
* module/ice-9/optargs.scm:
* module/ice-9/poll.scm:
* module/ice-9/receive.scm:
* module/ice-9/threads.scm:
* module/ice-9/vlist.scm:
* module/language/assembly/compile-bytecode.scm:
* module/language/ecmascript/compile-tree-il.scm:
* module/language/tree-il.scm:
* module/oop/goops.scm:
* module/oop/goops/simple.scm:
* module/oop/goops/stklos.scm:
* module/srfi/srfi-1.scm:
* module/srfi/srfi-35.scm:
* module/srfi/srfi-39.scm:
* module/srfi/srfi-45.scm:
* module/srfi/srfi-67/compare.scm:
* module/sxml/match.scm:
* module/system/repl/error-handling.scm:
* module/system/repl/repl.scm:
* module/system/vm/inspect.scm:
* module/texinfo.scm:
* module/web/server.scm: Use define-syntax-rule, where it makes sense.
2011-09-02 11:36:14 +02:00
Andy Wingo
2b582a285a (web http): locale-independent parsing and serialization of dates
* 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.
2011-08-04 15:07:27 +02: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
037a680321 ensure presence of Host header in HTTP/1.1 requests
* module/web/request.scm (build-request): Make sure that HTTP/1.1
  requests have the Host header set, per RFC 2616 section 9.

* test-suite/tests/web-request.test ("example-1"): Add test.
2011-07-15 13:36:52 +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
Andy Wingo
a964aa62c2 web server more assiduous about closing ports
* module/web/uri.scm:
* module/web/server.scm (call-with-output-string*):
  (call-with-output-bytevector*): Local procs to output to strings or
  bytevectors, *and then close the port*.  We can't make this change in
  call-with-output-string because it would be incompatible.

* module/web/uri.scm (call-with-encoded-output-string, decode-string)
  (uri-decode)
* module/web/server.scm (call-with-encoded-output-string): Use the new
  helpers.
2011-02-24 11:10:49 +01:00
Andy Wingo
6854c32480 core modules use (ice-9 binary-ports) instead of (rnrs io ports)
* module/language/assembly/compile-bytecode.scm:
* module/language/elisp/lexer.scm:
* module/web/request.scm:
* module/web/response.scm:
* module/web/server.scm:
* module/web/uri.scm: Use ice-9 binary-ports.
2011-02-18 16:01:25 +01:00
Andy Wingo
f944ee8f23 request and response cleanups
* module/web/request.scm (build-request): Make URI a positional
  argument.

* module/web/response.scm: Remove extend-response.
  (read-response): Fix a docstring.
* module/web/server.scm (extend-response): Include extend-response here,
  but not exported.
2011-01-10 22:44:41 -08:00
Andy Wingo
3475fbb572 (web response) and (web request): bodies are bytevectors
* module/web/request.scm (read-request-body, write-request-body): Rename
  from read-request-body/bytevector and
  write-request-body/bytevector.  Remove the /latin-1 variants, as they
  were unused and a bad idea.
* module/web/response.scm (read-response-body, write-response-body):
  Likewise.

* module/web/server/http.scm (http-read, http-write): Adapt to
  request/response change.

* test-suite/tests/web-request.test:
* test-suite/tests/web-response.test: Update tests.
2011-01-10 22:44:36 -08:00
Andy Wingo
ecfb7167cb parse credentials and challenges
* module/web/http.scm (parse-credentials, validate-credentials)
  (write-credentials, parse-challenge, parse-challenges)
  (validate-challenges, write-challenge, write-challenges)
  (declare-credentials-header!, declare-challenge-list-header!): New
  helpers.
  ("Authorization", "Proxy-Authorization"): Parse out credentials.
  ("Proxy-Authenticate", "WWW-Authenticate"): Parse out challenges.
2011-01-10 09:31:29 -08:00
Andy Wingo
94f16a5b8f more symbols in (web http)
* module/web/http.scm (declare-symbol-list-header!): New helper.
  ("Connection"): Redefine as a header list.
  ("Allow", "Content-Encoding", "Accept-Ranges"): Redefine as symbol
  lists.

* test-suite/tests/web-http.test:
* test-suite/tests/web-response.test: Adapt tests.
2011-01-08 21:32:14 -08:00
Andy Wingo
0acc595b94 (web http): keys are always symbols
* module/web/http.scm (parse-media-type): Parse media types as symbols.
  (parse-key-value-list, parse-param-component, parse-param-list):
  Change kons to val-parser. Always parse keys as symbols, and always
  either cons, if there is a val, or just have the key, if there is no
  val.  Easier to explain and just as correct.
  (declare-param-list-header!, declare-key-value-list-header!): Adapt to
  key-list and param-list kons change.
  ("Cache-Control", "Pragma", "Transfer-Encoding", "Accept", "Expect")
  ("TE"): Likewise, adapt.
  ("Content-Type"): Param keys are symbols.
2011-01-08 20:50:46 -08:00
Andy Wingo
7118eccd72 (web http): don't expose header-decl objects
* module/web/http.scm: Change to not expose the header-decl objects,
  instead exposing header-parse, header-validator, header-writer et al.
  Explaining header decls in the manual was too complicated.
  (string->header, header->string): New helpers.
  (<header-decl>): Remove the `sym' field.
  (declare-header!): Adapt to header-decl change, and use
  string->header.
  (known-header?, header-parser, header-validator, header-writer): New
  procedures.

  Adapt to use the new procedures internally.
2011-01-08 11:40:20 -08:00
Andy Wingo
be1be3e597 (web http): header names always represented as symbols
* module/web/http.scm (declare-header!): No need to specify `sym', as it
  can be derived from `name'. Change to take parser, validator, and
  writer as positional arguments, and multiple? as a keyword.
  (parse-header): Change to take the header as a symbol already, and
  just return the parsed value.  All headers are symbols now, including
  unknown headers.  I feel OK doing this given that the symbol GC works
  now.
  (lookup-header-decl): Only look up headers by symbol.
  (read-header): Adapt to parse-header change.

  (valid-header?, write-header): Adapt to all headers being symbols.
  (split-header-names, list-of-header-names?, write-header-list):
  Represent all header names as symbols.

  (declare-opaque-header!, declare-date-header!)
  (declare-string-list-header!, declare-header-list-header!)
  (declare-integer-header!, declare-uri-header!)
  (declare-quality-list-header!, declare-param-list-header!)
  (declare-key-value-list-header!, declare-entity-tag-list-header!):
  Change to be functions instead of syntax, and no need to specify the
  symbolic name. Update all header declarations accordingly.

* module/web/request.scm (validate-headers):
* module/web/response.scm (validate-headers): Adapt to all headers being
  symbols.

* test-suite/tests/web-http.test (pass-if-parse, pass-if-any-error)
  (pass-if-parse-error): Update for parse-header change.
  ("general headers"): Update header list examples to be all symbols.
2011-01-08 10:54:07 -08:00
Andy Wingo
929ccf48fc read-header returns EOF at end, update (web http) docs
* doc/ref/web.texi (HTTP): Add an example for declaring a header, and
  adapt to read-header change.

* module/web/http.scm (read-header): Return EOF for both values if there
  are no more headers, instead of #f.
  (read-headers): Adapt.
2011-01-07 09:18:36 -08:00
Andy Wingo
91b320fe16 uri-encode fast path
* module/web/uri.scm (uri-encode): Add a fast-path for the common case
  in which the string does not contain any reserved characters.
2011-01-07 09:18:36 -08:00
Andy Wingo
7d6b8b75fc uri-decode #:encoding, not #:charset
* module/web/uri.scm (call-with-encoded-output-string, encode-string)
  (decode-string, uri-decode, uri-encode): Change all instances of
  "charset" to "encoding", as variables and arguments.
2011-01-07 09:18:36 -08:00
Andy Wingo
8745c33afb rename string->uri and uri->string.
* module/web/uri.scm (string->uri, uri->string): Rename from parse-uri
  and unparse-uri.

* test-suite/tests/web-uri.test:
* module/web/http.scm: All callers changed.
2011-01-07 09:18:36 -08:00
Andy Wingo
e2d4bfea00 build-response validates headers
* module/web/response.scm (build-response): Add some validation, like
  for build-request.
2010-12-17 12:01:34 +01:00
Andy Wingo
adc91e41bf http: lists of header names parse better
* module/web/http.scm (list-of-strings?, write-list-of-strings): Move
  definitions up.
  (split-header-names, list-of-header-names?, write-header-list): New
  helpers.
  (declare-header-list-header): New helper.
  (cache-control): Use split-header-names for private and no-cache.
  (trailer): Use declare-header-list-header to parse known headers to
  symbols.
  (vary): Likewise, use split-header-names et al.

* test-suite/tests/web-http.test ("general headers"): Add a test.
2010-12-16 18:12:14 +01:00
Andy Wingo
25731543d4 better cache-control: private, no-cache parsing
* module/web/http.scm (cache-control): Parse private and no-cache
  better.
* test-suite/tests/web-http.test ("general headers"): Update.
2010-12-16 17:56:03 +01:00
Andy Wingo
43d6659ae2 (web server) docstrings
* module/web/server.scm: Docstrings in the house.
2010-12-16 14:48:35 +01:00
Andy Wingo
cc1e26c2cd docstrings in (web request) and (web response)
* module/web/request.scm:
* module/web/response.scm: Add docstrings.
2010-12-16 14:48:34 +01:00
Andy Wingo
92c5c0b67c (web http) docstrings
* module/web/http.scm: Add docstrings all around.
2010-12-16 14:48:34 +01:00
Andy Wingo
277bbe9624 document (web uri), and simplify uri-encode
* module/web/uri.scm: Add docstrings.
  (uri-encode): Simplify. Not sure what I was thinking before.
2010-12-16 14:48:34 +01:00
Andy Wingo
998191fd4f fix testing code in web/server
* module/web/server.scm (call-with-encoded-output-string): Fix some code
  I accidentally left in while testing. Re-tested the difference in
  speed; pleasantly surprised.

* module/web/uri.scm: Make the same change here.
2010-12-12 23:34:18 +01:00
Andy Wingo
ec3c7570d8 http-read robustness
* module/web/server/http.scm (http-read): Record the client index in
  more cases in which code could throw an error.
2010-12-12 21:59:29 +01:00
Andy Wingo
c7857da63a (web uri) can uri-decode non-utf-8 payloads
* module/web/uri.scm (call-with-encoded-output-string, encode-string):
  Copy from server.scm
  (decode-string): Copy from tekuti.
  (uri-decode): The #:charset arg is a string, like
  port-encoding. Support other charsets.
  (uri-encode): Charset is a string. Other encodings still not nicely
  supported. Hmm.
2010-12-11 19:19:41 +01:00
Andy Wingo
4595600a08 http-read calls setvbuf only once
* module/web/server/http.scm (http-read): Don't play the setvbuf dance,
  it was throwing away buffered input. Instead just call setvbuf once
  before doing any reads or writes.
2010-12-06 19:52:51 +01:00
Andy Wingo
a9a2065540 fix name...
* module/web/request.scm (read-request-body/latin-1): Fix name...
2010-12-06 15:32:13 +01:00
Andy Wingo
e46f69e25c fix read-{request,response}-body/latin-1
* module/web/request.scm (read-response-body/latin-1):
* module/web/response.scm (read-response-body/latin-1): Avoid the
  craziness of the read-delimited! interface and hand-roll our
  own. Fixes errors if read-delimited returns #f or EOF.
2010-12-06 15:30:45 +01:00
Andy Wingo
9eed1010e7 leniency regarding quality values in http.scm
* module/web/http.scm: Add commentary.
  (parse-quality): Allow .NNN to be interpreted as 0.NNN.

* test-suite/tests/web-http.test ("request headers"): Add a test.
2010-12-06 13:52:56 +01:00
Andy Wingo
adcd58543c fix entity tag writing
* module/web/http.scm (write-entity-tag): Fix writing of entity tags
  (strong versus weak).
2010-12-06 12:58:16 +01:00
Andy Wingo
b500ced6b8 more robustness in http-read
* module/web/server/http.scm (http-read): If there was an error reading
  the request, be sure to close the request port.
2010-12-06 11:24:48 +01:00
Andy Wingo
4164be30d3 http doesn't keep-alive requests for which there was an error
* module/web/server/http.scm (keep-alive?): Don't keep the client around
  if there is an error.
2010-12-05 20:24:14 +01:00
Andy Wingo
e8c44a044f (web server http) comment
* module/web/server/http.scm: Add comment about charsets.
2010-12-04 19:45:51 +01:00
Andy Wingo
f3d390939b fix error handling in read-{request,response}-body/latin-1
* module/web/request.scm (read-request-body/latin-1):
* module/web/response.scm (read-response-body/latin-1): Detect short
  reads instead of returning a full buffer with the last bits zeroed
  out. (Before the make-string commit, they contained uninitialized
  memory, which was a fairly serious error.)
2010-12-04 19:45:09 +01:00
Andy Wingo
80993fa438 http server impl reads body as a bytevector by default
* module/web/server/http.scm (http-read): Read body as a bytevector by
  default. That way we punt encoding issues to the app.
2010-12-03 17:37:22 +01:00
Andy Wingo
35b97af9d6 remove redundant error-handling block
* module/web/server/http.scm (http-read): No need for a
  call-with-error-handling block here, as the read impl is itself within
  an error-handling block.
2010-12-03 16:41:46 +01:00
Andy Wingo
e6ae317306 web server micro-tuning
* module/web/server/http.scm (http-open): Allow up to 128 pending
  connections -- the default value for somaxconn on a number of
  machines. This is from the HOP paper.
  (http-read): Set the send buffer to 12 KB, also from the HOP paper.
2010-12-03 16:30:52 +01:00
Andy Wingo
0baead3f6e reverse order of poll-set traversal in http-read
* module/web/server/http.scm (http-read): Rewrite to iterate down the
  pollset, so the vector shuffles touch less memory and the end
  condition of the loop is clearer.
2010-12-03 16:11:37 +01:00
Andy Wingo
462a1a04cf (web server) punts keep-alive to impls; http server uses (ice-9 poll)
* module/web/server.scm: Rewrite to remove the extra "keep-alive"
  parameter. Instead, since the server is an essentially stateful
  object, have clients that want to do keep-alive manage that set as
  part of the server state. Also avoids imposing a particular data
  structure on the server implementation.

* module/web/server/http.scm: Adapt to the new server interface. Also,
  use a poll set instead of select and lists. Makes handling 1000
  clients at a time much more possible.
2010-12-03 15:31:57 +01:00
Andy Wingo
8bf6cfea71 add some debugging to (web server)
* module/web/server.scm: Add some basic elapsed-time debugging, but only
  if you flip a switch to turn it on at expand-time.
2010-12-02 13:36:04 +01:00
Andy Wingo
bb90ce2cbc better socket buffering on http web server backend
* module/web/server/http.scm (http-read, http-write): Line-buffer the
  port while we're reading the request, and block-buffer it otherwise
  Use the default block size.
2010-12-02 13:33:49 +01:00
Andy Wingo
af0da6ebe7 (web server) supports non-utf-8 charsets
* module/web/server.scm (sanitize-response): Support charsets other than
  utf-8. Oddly collecting a string and converting it to utf-8 appears to
  be faster than collecting a utf-8 bytevector directly.
2010-12-02 12:28:35 +01:00