Changeset 34366 in project


Ignore:
Timestamp:
08/25/17 21:11:02 (4 weeks ago)
Author:
sjamaan
Message:

http-client: Document new [default-]prepare-request parameters

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/4/http-client

    r34311 r34366  
    239239This is the names, versions and comments of the software packages that
    240240the client is using, for use in the {{user-agent}} header which is
    241 automatically added to each request.
     241automatically added to each request by {{prepare-request}}.
    242242
    243243Defaults to {{(("Chicken Scheme HTTP-client" VERSION #f))}}, where
    244244{{VERSION}} is the version of this egg.
     245
     246==== Customising requests
     247
     248Given that http-client tries to do a lot "automagically", there will
     249be occasions where you want more control.  One way to do that is to
     250use {{call-with-response}}, but it's very low-level, so you'll end up
     251reimplementing a lot of the functionality that
     252{{call-with-input-request}} and {{with-input-from-request}} offer.
     253
     254Instead, http-client offers a parameter that allows you to tweak the
     255request just before a connection is made:
     256
     257<parameter>(prepare-request [preparer])</parameter>
     258
     259Here, {{preparer}} is a procedure which will be called every time a
     260connection is made.  This includes every request in a redirect chain,
     261so you can decide for every URL in the chain what to do with the
     262request.  The procedure receives and must return an intarweb request
     263object.  The default implementation is {{default-prepare-request}}.
     264
     265'''CAVEAT''': If you decide to change the request-uri last-minute, you
     266must also set the {{host}} header, because it will have already been
     267initialized to the request-uri's host attribute.
     268
     269<procedure>(default-prepare-request req)</procedure>
     270
     271This is the default implementation of the {{prepare-request}}
     272parameter.  It sets the {{User-Agent}} header from the
     273{{client-software}} parameter and adds {{set-cookie}} headers which
     274belong to the server and path from the request-uri.
    245275
    246276
     
    521551=== Changelog
    522552
    523 * trunk Enable SNI support for newly released openssl egg 1.9.0, use saner defaults like actually checking certificates.
     553* trunk Enable SNI support for newly released openssl egg 1.9.0, use saner defaults like actually checking certificates. Add {{prepare-request}} procedure (thanks to [[/users/caolan-mcmahon|Caolan McMahon]])
    524554* 0.12.2 Tweak test timeouts some more.
    525555* 0.12.1 Tweak test timeouts so they hopefully won't fail as fast on Salmonella runs.
Note: See TracChangeset for help on using the changeset viewer.