(rfc http2) - HTTP/2 client

Library (rfc http2)

This library provides simple client HTTP/2 defined in RFC 7540.

The library does not support Upgrade header defined in HTTP/1.1. Thus users must know if the server supports HTTP/2 or not, ahead.

Following is the simple example to send GET method to a HTTP/2 server.

(import (rfc http2))

(define conn (make-http2-client-connection "twitter.com" "443" :secure? #t))
(http2-get conn "/")
;; -> returns 2 values
;; header
;; body
(close-http2-client-connection! conn)
Function http2-client-connection? obj

Returns #t if the given obj is an HTTP/2 client connection, otherwise #f.

Function make-http2-client-connection server port :key (secure? #f) user-agent

Creates an HTTP/2 client connection.

The server must be a string indicating an existing server name.

The post must be a string of either port number or service.

The keyword argument secure? specifies to use TLS or not.

The keyword argument user-agent specifies the value of user-agentheader. The default value is Sagittarius- followed by version number.

NOTE: The connection does not guess if it should use secure connection or not by looking at port number or service name. Which means, even if you specify "https" or "443" however secure? keyword argument must be passed.

NOTE2: Created connections hold opened socket.

Function close-http2-client-connection! conn

Closes given HTTP/2 connection.

High level APIs

Sends HTTP/2 GET request to given uri of HTTP/2 client connection conn and returns 2 values of the response, header and content.

The rest arguments headers must be a list of keyword and string. The procedure sends these pairs as extra headers.

If the keyword argument receiver is specified, then the procedure uses given receiver to receive data. The default value is (make-gzip-receiver).

If the keyword argument redirect-handler is specified, then the procedure uses given redirect-handler to handle redirection.

Sends HTTP/2 POST request to given uri of HTTP/2 client connection conn with given data and returns 2 values of the response, header and content. data must be a bytevector.

The rest arguments headers must be a list of keyword and string. The procedure sends these pairs as extra headers.

The keyword arguments receiver and redirect-handler are the same as http2-get.

Sends HTTP/2 HEAD request to given uri of HTTP/2 client connection conn and returns 2 values of the response, header and content.

The rest arguments headers must be a list of keyword and string. The procedure sends these pairs as extra headers.

The keyword arguments receiver and redirect-handler are the same as http2-get.

Sends an HTTP/2 request to given HTTP/2 client connection conn.

method must be a symbol.

sender must be a sender described below section.

receiver must be a receiver described below section.

redirect-handler is the same as http2-get.

The procedure returns a list of response header and content.

HTTP/2 sender

A sender is a procedure which accepts 2 arguments, internal HTTP/2 stream and flag. At this moment, the internal HTTP/2 stream is not exposed so users cannot create own sender.

Returns a sender which sends given header as HTTP/2 header.

Returns a sender which sends given data as HTTP/2 data.

Returns a composite sender.

HTTP/2 receiver

A receiver is a procedure which accepts 4 arguments, internal HTTP/2 stream, header, frame and flag. The same restriction as sender is applied, thus users cannot create own receiver, at this moment.

Returns a receiver which receives HTTP/2 data frame and put the value into sink. When the stream reaches to the end, then _flusher_is called with sink.

Returns a receives which receives HTTP/2 data frame as a bytevector.

Returns a receives which receives HTTP/2 data frame and returns empty bytevector.

Returns a receives which receives HTTP/2 data frame. If the data frame is compressed to gzip, then the returning receiver expand the data and forward to the given receiver. If the data frame is not compressed, then it simply forward the data frame to the given receiver.

Convenient procedure whose definition is the following:

(http2-gzip-receiver (http2-binary-receiver))