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

94 commits

Author SHA1 Message Date
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
Andy Wingo
d41c62f579 fix up toy-server error handling
* module/web/toy-server.scm (serve-client): Fix up error handling, so we
  catch errors when reading, handling, and writing. If we run
  interactively, an error will enter the debugger.
2010-11-06 00:36:45 +01:00
Andy Wingo
e414bf2178 add toy web server
* module/web/toy-server.scm: New module, a toy web server.

* module/Makefile.am: Adapt.
2010-11-05 00:31:40 +01:00
Andy Wingo
a9eeb2f461 add HTTP response module
* module/web/response.scm: New module, for HTTP responses.
* test-suite/tests/web-response.test: Test suite.

* module/Makefile.am:
* test-suite/Makefile.am: Adapt.
2010-11-05 00:31:40 +01:00
Andy Wingo
ad05d4e8c6 add HTTP request module
* module/web/request.scm: Add HTTP request module.
* test-suite/tests/web-request.test: Test cases.

* module/Makefile.am:
* test-suite/Makefile.am: Adapt.
2010-11-05 00:31:36 +01:00
Andy Wingo
440840c113 add HTTP module
* module/web/http.scm: New module, declares known HTTP headers, and
  their parsers and unparsers.

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

* module/Makefile.am:
* test-suite/Makefile.am: Adapt.
2010-11-04 22:52:47 +01:00
Andy Wingo
5a2f7fb315 URI parsing errors throw to `uri-error'
* module/web/uri.scm (uri-error): New proc, throws to 'uri-error.
  (validate-uri, uri-decode, uri-encode): Use uri-error.

* test-suite/tests/web-uri.test: Update for uri-error.
2010-11-04 22:52:47 +01:00
Andy Wingo
73124c6c63 web/uri: reimplement for rfc 3986, add tests
* module/web/uri.scm: Reimplement for RFC 3986.

* module/Makefile.am: Add to build.

* test-suite/Makefile.am:
* test-suite/tests/web-uri.test: Add tests.
2010-10-17 20:35:22 +02:00
Andy Wingo
15c9af8c71 import uri.scm from tekuti, from guile-www 2010-10-17 20:35:22 +02:00