* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.)
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.