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

208 commits

Author SHA1 Message Date
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
Andy Wingo
a0ad8ad16c http web server impl ignores SIGPIPE
* module/web/server/http.scm (http-open): Ignore SIGPIPE. Keeps the
  server from dying in some circumstances.
2010-12-01 10:13:30 +01:00
Andy Wingo
c637190203 stub fixes to http 1.0 support in the web server
* module/web/server.scm (read-client): Fix number of returned values in
  the case in which there is an error reading the client.
  (sanitize-response): Add a case to adapt the reponse to the request
  version.
  (handle-request): Sanitize the response within an error-handling
  block.
  (serve-one-client): Move sanitation out of here.

* module/web/server/http.scm (keep-alive?): A more proper detection on
  whether we should support persistent connections.

* module/web/response.scm (adapt-response-version): New routine, to
  adapt a response to a given version. Currently a stub.
2010-12-01 10:13:30 +01:00
Andy Wingo
612aa5bee8 fix web server bugs
* module/web/http.scm (valid-quality?):
* module/web/server.scm (sanitize-response): Fix a couple bugs.
2010-11-23 16:02:21 +01:00
Andy Wingo
a4342ba826 fix up a couple content-length issues in web/server.scm:sanitize-response
* module/web/server.scm (sanitize-response): Allow body to be #f. Don't
  require or insert a content-length if there is no body.
2010-11-22 23:58:24 +01:00
Andy Wingo
d9f00c3db5 flesh out (web server)'s sanitize-response
* module/web/server.scm (sanitize-response): Flesh out. If we get a
  string, we encode it to a bytevector using the encoding snarfed from
  the response. We should check the request, though...
2010-11-13 18:31:34 +01:00
Andy Wingo
3d95977991 add extend-response.
* module/web/response.scm (extend-response): New utility.
2010-11-13 18:30:27 +01:00
Andy Wingo
7aa54882cf (web http) parses content-type as "foo/bar", not "foo" "bar"
* module/web/http.scm (parse-media-type, validate-media-type,
  (content-type): Change to represent media types as ("foo/bar" ("param"
  . "val") ...) instead of ("foo" "bar" ("param" . "val") ...). Seems to
  be more in line with what people expect.

* test-suite/tests/web-http.test ("entity headers"): Add content-type
  test.

* test-suite/tests/web-response.test ("example-1"): Adapt expected
  parse.
2010-11-13 18:25:34 +01:00
Andy Wingo
347ba27e4b remove (web toy-server)
* module/Makefile.am
* module/web/toy-server.scm: Remove. It's not so much that the new (web
  server) stuff is not a toy, it's that users are expected to use the
  new backends (mod-lisp, etc) in "production".
2010-11-12 17:16:36 +01:00
Andy Wingo
79ef79ee34 add generic web server with http-over-tcp backend
* module/web/server.scm: New generic web server module, with support for
  different backends. An HTTP-over-TCP backend is the only one included
  with Guile, though one can imagine FastCGI, mod-lisp, mongrel2/0mq etc
  backends as well.

* module/web/server/http.scm: The aforementioned HTTP backend.
2010-11-12 17:16:36 +01:00
Andy Wingo
d4b6200a0a add request-meta
* module/web/request.scm (<request>): Add `meta' field and accessor, for
  metadata like the server IP, the client IP, CGI environment variables,
  etc.
  (build-request): Add meta kwarg.
  (read-request): Add meta optional arg.
  (write-request): Adapt.
2010-11-12 17:16:36 +01:00
Andy Wingo
13b7e2a6e6 more (web http) exports for parsing request components
* module/web/http.scm (lookup-header-decl): New exported function.
  (parse-http-version, parse-http-method, parse-request-uri): Export
  these functions.
2010-11-12 17:16:36 +01:00
Andy Wingo
4eb7c8f004 unparse-uri avoids serializing e.g. :80 in http:// uris
* module/web/uri.scm (declare-default-port!): New function, declares a
  default port for a scheme. Predeclare default ports for http and
  https.
  (unparse-uri): If the port is the default port for the given scheme,
  don't serialize the port part of the URI.
2010-11-12 17:16:35 +01:00