Opened 7 years ago
Closed 7 years ago
#1392 closed defect (fixed)
Ability to customise http-client headers for each request
Reported by: | Caolan McMahon | Owned by: | sjamaan |
---|---|---|---|
Priority: | major | Milestone: | someday |
Component: | extensions | Version: | 4.12.0 |
Keywords: | http-client | Cc: | |
Estimated difficulty: |
Description
I propose adding a (prepare-request) parameter to the http-client egg. This allows me to add etag and if-modified-since headers to all (even redirected) requests made by http-client, based on the current request URI.
-
http-client.scm
43 43 basic-authenticator digest-authenticator 44 44 determine-username/password determine-proxy 45 45 determine-proxy-from-environment determine-proxy-username/password 46 server-connector default-server-connector) 46 server-connector default-server-connector 47 prepare-request default-prepare-request) 47 48 48 49 (import chicken scheme lolevel) 49 50 (use srfi-1 srfi-13 srfi-18 srfi-69 … … 333 334 (when (> (read-string! (string-length buf) buf port) 0) 334 335 (loop #f))))))) 335 336 336 (define ( add-headersreq)337 (define (default-prepare-request req) 337 338 (let* ((uri (request-uri req)) 338 339 (cookies (get-cookies-for-uri (request-uri req))) 339 340 (h `(,@(if (not (null? cookies)) `((cookie . ,cookies)) '()) 340 (host ,(cons (uri-host uri) (and (not (uri-default-port? uri))341 (uri-port uri))))342 341 ,@(if (and (client-software) (not (null? (client-software)))) 343 342 `((user-agent ,(client-software))) 344 343 '())))) … … 345 344 (update-request req 346 345 headers: (headers h (request-headers req))))) 347 346 347 (define prepare-request (make-parameter default-prepare-request)) 348 348 349 (define (http-client-error loc msg args specific . rest) 349 350 (raise (make-composite-condition 350 351 (make-property-condition 'exn 'location loc 'message msg 'arguments args) … … 587 588 (let* ((uri (request-uri req)) 588 589 (con (ensure-connection! uri))) 589 590 (condition-case 590 (let* ((req (add-headers (update-request 591 req port: (http-connection-outport con)))) 591 (let* ((req ((prepare-request) 592 (update-request 593 req 594 headers: (headers 595 `((host ,(cons (uri-host uri) 596 (and (not (uri-default-port? uri)) 597 (uri-port uri))))) 598 (request-headers req)) 599 port: (http-connection-outport con)))) 592 600 ;; No outgoing URIs should ever contain credentials or fragments 593 601 (req-uri (update-uri uri fragment: #f username: #f password: #f)) 594 602 ;; RFC1945, 5.1.2: "The absoluteURI form is only allowed
Attachments (1)
Change History (2)
Changed 7 years ago by
Attachment: | prepare-request2.diff added |
---|
comment:1 Changed 7 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
Note: See
TracTickets for help on using
tickets.
Implemented in trunk, will be part of 0.13