Changeset 34365 in project


Ignore:
Timestamp:
08/25/17 20:53:03 (4 weeks ago)
Author:
sjamaan
Message:

http-client: Add new "prepare-request" parameter to tweak headers and other request attribs before sending the request

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/4/http-client/trunk/http-client.scm

    r34310 r34365  
    4444     determine-username/password determine-proxy
    4545     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)
    4748
    4849(import chicken scheme lolevel)
     
    334335              (loop #f)))))))
    335336
    336 (define (add-headers req)
     337(define (default-prepare-request req)
    337338  (let* ((uri (request-uri req))
    338339         (cookies (get-cookies-for-uri (request-uri req)))
    339340         (h `(,@(if (not (null? cookies)) `((cookie . ,cookies)) '())
    340               (host ,(cons (uri-host uri) (and (not (uri-default-port? uri))
    341                                                (uri-port uri))))
    342341              ,@(if (and (client-software) (not (null? (client-software))))
    343342                    `((user-agent ,(client-software)))
     
    345344    (update-request req
    346345                    headers: (headers h (request-headers req)))))
     346
     347(define prepare-request (make-parameter default-prepare-request))
    347348
    348349(define (http-client-error loc msg args specific . rest)
     
    588589           (con (ensure-connection! uri)))
    589590      (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))))
    592600                 ;; No outgoing URIs should ever contain credentials or fragments
    593601                 (req-uri (update-uri uri fragment: #f username: #f password: #f))
Note: See TracChangeset for help on using the changeset viewer.