Opened 11 months ago
Last modified 11 months ago
#1849 new defect
http-client: with-input-from-request fails when uri-or-request is an intarweb request
| Reported by: | Pietro Cerutti | Owned by: | |
|---|---|---|---|
| Priority: | major | Milestone: | someday |
| Component: | extensions | Version: | 5.3.0 |
| Keywords: | http-client | Cc: | |
| Estimated difficulty: | easy |
Description
(import (chicken io) (intarweb) (http-client)) (let ((req (make-request uri: "https://google.com"))) (with-input-from-request req #f read-string))
Error: (call-with-input-request) The first argument must be either an uri-common object, an intarweb request object, or an URI string
#<intarweb#request>
#f
#<procedure (f6040 p10826038 r10836039)>
Call history:
<syntax> (##core#begin (with-input-from-request req #f read-string))
simple-req.scm:3 (with-input-from-request req #f read-string)
simple-req.scm:2 (make-request #:uri "https://google.com")
simple-req.scm:2 (make-request #:uri "https://google.com")
simple-req.scm:3 (with-input-from-request req #f read-string)
http-client.scm:903: call-with-input-request*
http-client.scm:803: uri-common#uri-reference?
http-client.scm:805: intarweb#request?
http-client.scm:805: intarweb#request-uri
http-client.scm:807: uri-common#uri?
http-client.scm:810: uri-common#uri-reference?
http-client.scm:808: http-client-error
http-client.scm:344: chicken.condition#make-property-condition
http-client.scm:345: chicken.condition#make-property-condition
http-client.scm:343: chicken.condition#make-composite-condition
http-client.scm:343: srfi-18#raise <--
Here, we take the request-uri out of the intarweb request. That results in a string. Two lines below, we expect it to be an uri and we fail.
Note:
See TracTickets
for help on using tickets.

This is strictly speaking a user error - the intarweb request object should only have a full uri-common object for the "uri" field.
From the docs on intarweb:
I think the problem here is that the constructor doesn't do any type checking, so the error is propagated and shows up as a http-client error. I'll see if I can improve intarweb to check its arguments in the constructor. I'm not sure this can be done so easily as it's basically a simple "defstruct" structure, so it also has setters and functional update which would also have to do the checking...