On this page:
http-client-base<%>
async-request
http-connection-manager%
new
get-connection
open-connection
async-request
http-connection%
new
get-actual-connection
open-actual-connection
make-http1-connection
make-http2-connection
close
async-request
http-actual-connection<%>
abandon
open-request
open?
8.12

9 Internals🔗ℹ

Warning: This section describes internal implementation details that may change without warning. Contact the author before relying on this module.

 (require http123/internal) package: http123-lib

Interface of objects that can implement the basic client operation of submitting a request. The method async-request in http-client<%> is implemented by forwarding it to an object implementing this interface (usually an instance of http-connection-manager%).

method

(send a-http-client-base async-request req)

  (evt/c (-> (is-a?/c response<%>)))
  req : request?
Sends the request req and returns an event that becomes ready when the server either sends a response or when an error occurs. See also async-request.

class

http-connection-manager% : class?

  superclass: object%

  extends: http-client-base<%>
Handles a request by creating connections (http-connection%) based on the request’s location.

constructor

(new http-connection-manager% 
    [[ssl ssl] 
    [custodian custodian]]) 
  (is-a?/c http-connection-manager%)
  ssl : (or/c 'secure 'auto ssl-client-context?) = 'secure
  custodian : custodian? = (current-custodian)

method

(send a-http-connection-manager get-connection loc)

  (is-a?/c http-connection%)
  loc : ok-http-url?
Returns the existing connection to the server specified by loc, or creates a new connection using open-connection if none exists yet. Connections are identified by the triple consisting of the location’s host, port, and scheme (https vs http).

method

(send a-http-connection-manager open-connection host 
  port 
  https?) 
  (is-a?/c http-connection%)
  host : string?
  port : (integer-in 1 (sub1 (expt 2 16)))
  https? : boolean?
Creates a new connection to the server at host:port, using SSL/TLS if https? is true.

method

(send a-http-connection-manager async-request req)

  (evt/c (-> (is-a?/c response<%>)))
  req : request?
Equivalent to
(send (send a-http-connection-manager get-connection (request-url req))
      async-request req)

class

http-connection% : class?

  superclass: object%

  extends: http-client-base<%>
Represents a connection to a specific server. A connection can be open or closed; if a request is made to a closed connection, it is automatically reopened by creating a new actual connection.

constructor

(new http-connection% 
    [host host] 
    [port port] 
    [ssl ssl] 
    [[protocols protocols]] 
    [custodian custodian]) 
  (is-a?/c http-connection%)
  host : string?
  port : (integer-in 1 (sub1 (expt 2 16)))
  ssl : (or/c #f 'secure 'auto ssl-client-context?)
  protocols : (listof symbol?) = '(http/2 http/1.1)
  custodian : custodian?

method

(send a-http-connection get-actual-connection [connect?])

  http-actual-connection?
  connect? : boolean? = #t
Gets the existing actual connection to the server. If none currently exists, one is created using open-actual-connection if connect? is true, or #f is returned otherwise.

method

(send a-http-connection open-actual-connection)

  (is-a?/c http-actual-connection<%>)
Creates a new actual connection to the server.

method

(send a-http-connection make-http1-connection)

  (is-a?/c http-actual-connection<%>)
Creates an actual connection implementing the HTTP/1.1 protocol.

method

(send a-http-connection make-http2-connection)

  (is-a?/c http-actual-connection<%>)
Creates an actual connection implementing the HTTP/2 protocol.

method

(send a-http-connection close)  void?

Closes the current actual connection, if one exists.

method

(send a-http-connection async-request req)

  (evt/c (-> (is-a?/c response<%>)))
  req : request?
Submits the request to (get-actual-connection) using open-request. If the request submission fails, the current actual connection is abandoned and the request is retried with a new actual connection. If it fails too many times, an exception is raised.

Represents an actual communication channel to a server.

method

(send a-http-actual-connection abandon)  void?

Marks the actual connection as closed. It no longer accepts new requests, but it continues to receive responses until the server hangs up.

method

(send a-http-actual-connection open-request req)

  (or/c #f (evt/c (-> (is-a?/c response<%>))))
  req : request?
Submits the request to the server and returns an event, or returns #f if the submission failed (for example, if the connection was concurrently closed).

method

(send a-http-actual-connection open?)  boolean?

Returns #t if the connection is still fully open—that is, new requests can be sent to the server—or #f if the connection is closed or half-open.