Summary
http-client: with-input-from-request fails when uri-or-request is an intarweb request
Metadata
- Id: 8ffc49188774e623c868e1d08fd1680b1bd1a66c
- Trac id: 1849
- Type: defect
- Reporter: gahr
- Owner:
- Cc:
- Status: new
- Component: extensions
- Estimated difficulty: easy
- Resolution:
- Priority: major
- Milestone: someday
- Version: 5.3.0
- Changetime: 2025-01-20 13:32:37 UTC
- Created: 2025-01-20 10:56:22 UTC
- Keywords: http-client
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.
https://code.call-cc.org/cgi-bin/gitweb.cgi?p=eggs-5-latest.git;a=blob;f=http-client/1.2.2/http-client.scm;h=58d045d661cdae7924afe4983f24dfb822d49dc3;hb=HEAD#l805
Changes and comments
[2025-01-20 13:32:37 UTC] sjamaan wrote:
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:
> The URI defines the entity to retrieve on the server, which should be a uri-common-type URI object.
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...