From: Josep Portella Florit <jpf@primfilat.com>
To: guile-devel@gnu.org
Subject: Comments on the web modules
Date: Sun, 01 Jun 2014 13:18:04 +0200 [thread overview]
Message-ID: <87lhtgc1zn.fsf@primfilat.com> (raw)
Hi!
I have some comments on the web modules:
1) The web server handlers receive a request object and the body as a
bytevector. I think it would be more flexible to pass the request
object only, and let the handler decide how to read the body from the
port of the request object; it would allow processing large bodies
without being bound by RAM.
2) The web server handlers must return a response object (or an alist of
headers) and a body, which may be a bytevector, a string or a procedure
that accepts a port argument. In the case of the procedure, the output
to the port is accumulated into a bytevector, and then written to the
client's port. I think it should be written to the client's port
directly; it would allow to write large bodies without being bound by
RAM. This would imply that, if the content-length is not set, the port
should be wrapped by a chunk-encoded port (I know you have already
thought about this, according to the `sanitize-response' documentation),
or else the connection should be closed after the procedure returns.
3) The web server should add the client's sock-addr to the meta alist
of the request object. I know you planned to do this, according to
the `request-meta' documentation and the (web server http) source.
Instead of taking the `cdr' of `accept's return value and storing it
somewhere, which would complicate the code, you could use
`getpeername' when building the request. I'm interested in this
because I wrote a procedure that creates request objects from CGI
requests, and I would like to make the meta information compatible.
4) `sanitize-response' adds a default charset parameter to the
response's content-type header when the body is a string or a
procedure, even if the content-type is not textual. See the code
below. I think it should only do this for textual content-types
(text/*).
Regards
### `sanitize-response' test
(use-modules (web server)
(web request)
(web response)
(web uri)
(rnrs io ports))
(define (sanitize-response-test body)
(call-with-values (lambda ()
(sanitize-response
(build-request (string->uri "http://test/"))
'((content-type . (application/octet-stream)))
body))
(lambda (response body)
(values (response-headers response)
body))))
(sanitize-response-test (lambda (port)
(put-bytevector port #vu8(1 2 3))))
=> ((content-length . 3)
(content-type application/octet-stream (charset . "utf-8")))
=> #vu8(1 2 3)
(sanitize-response-test "\x01\x02\x03")
=> ((content-length . 3)
(content-type application/octet-stream (charset . "utf-8")))
=> #vu8(1 2 3)
(sanitize-response-test #vu8(1 2 3))
=> ((content-length . 3)
(content-type application/octet-stream))
=> #vu8(1 2 3)
next reply other threads:[~2014-06-01 11:18 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-01 11:18 Josep Portella Florit [this message]
2014-06-03 7:58 ` Comments on the web modules Nala Ginrut
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87lhtgc1zn.fsf@primfilat.com \
--to=jpf@primfilat.com \
--cc=guile-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).