The experimental SPDY protocol version 2, 3 and 3.1 implementation in C
The experimental SPDY protocol version 2, 3 and 3.1 implementation in C
This is an experimental implementation of Google's SPDY protocol in C.
This library provides SPDY version 2, 3 and 3.1 framing layer implementation. It does not perform any I/O operations. When the library needs them, it calls the callback functions provided by the application. It also does not include any event polling mechanism, so the application can freely choose the way of handling events. This library code does not depend on any particular SSL library (except for example programs which depend on OpenSSL 1.0.1 or later).
This project also develops SPDY client, server and proxy on top of
Spdylay library. See SPDY Client and Server Programs_ section.
Most of the SPDY/2, SPDY/3 and SPDY/3.1 functionality has been implemented. In both versions, the direct support of server-push has not been available yet. The application can achieve server-push using primitive APIs though.
As described below, we can create SPDY client and server with the current Spdylay API.
The following packages are needed to build the library:
To build and run the unit test programs, the following packages are needed:
To build and run the example programs, the following packages are needed:
To enable -a option (getting linked assets from the downloaded
resource) in spdycat (one of the example program), the following
packages are needed:
To build SPDY/HTTPS to HTTP reverse proxy shrpx (one of the
example program), the following packages are needed:
If you are using Ubuntu 12.04, you need the following packages installed::
$ apt-get install autoconf automake autotools-dev libtool pkg-config zlib1g-dev libcunit1-dev libssl-dev libxml2-dev libevent-devBuilding from git is easy, but please be sure that at least autoconf 2.68 is used::
$ autoreconf -i
$ automake
$ autoconf
$ ./configure
$ makeTo build documentation, run::
$ make htmlThe documents will be generated under doc/manual/html/.
The generated documents will not be installed with make install.
In this section, we briefly describe how to build Android binary using
Android NDK _
cross-compiler on Debian Linux.
We offer android-config and android-make scripts to make the
build easier. To make these script work, NDK toolchain must be
installed in the following way. First, let introduce ANDROID_HOME
environment variable. We need to install toolchain under
$ANDROID_HOME/toolchain. An user can freely choose the path for
ANDROID_HOME. For example, to install toolchain under
$ANDROID_HOME/toolchain, do this in the the directory where NDK is
unpacked::
$ build/tools/make-standalone-toolchain.sh --platform=android-9 --install-dir=$ANDROID_HOME/toolchainThe platform level is not important here because we don't use Android specific C/C++ API.
The dependent libraries, such as OpenSSL and libevent should be built
with the toolchain and installed under $ANDROID_HOME/usr/local.
We recommend to build these libraries as static library to make the
deployment easier. libxml2 support is currently disabled.
We use zlib which comes with Android NDK, so we don't have to build it by ourselves.
Before running android-config and android-make,
ANDOIRD_HOME environment variable must be set to point to the
correct path.
After android-config, run android-make to compile sources.
android-make is just include path to cross compiler in PATH
and run make. So if you include path to corss compiler by yourself,
you can just run make to build spdylay and tools as usual.
The public API reference is available on online. Visit http://tatsuhiro-t.github.io/spdylay/. All public APIs are in spdylay/spdylay.h. All public API functions as well as the callback function typedefs are documented.
The src directory contains SPDY client and server implementations
using Spdylay library. These programs are intended to make sure that
Spdylay API is acutally usable for real implementation and also for
debugging purposes. Please note that OpenSSL with NPN _ support is
required in order to build and run these programs. At the time of
this writing, the OpenSSL 1.0.1 supports NPN.
Spdycat - SPDY client +++++++++++++++++++++
The SPDY client is called spdycat. It is a dead simple downloader
like wget/curl. It connects to SPDY server and gets resources given in
the command-line::
$ src/spdycat -h
Usage: spdycat [-Oansv23] [-t ] [-w ] [--cert=]
[--key=] [--no-tls] [-d ] [-m ] [-p ]
[-P ] ...
OPTIONS:
-v, --verbose Print debug information such as reception/
transmission of frames and name/value pairs.
-n, --null-out Discard downloaded data.
-O, --remote-name Save download data in the current directory.
The filename is dereived from URI. If URI
ends with '/', 'index.html' is used as a
filename. Not implemented yet.
-2, --spdy2 Only use SPDY/2.
-3, --spdy3 Only use SPDY/3.
--spdy3-1 Only use SPDY/3.1.
-t, --timeout= Timeout each request after seconds.
-w, --window-bits=
Sets the initial window size to 2**.
-a, --get-assets Download assets such as stylesheets, images
and script files linked from the downloaded
resource. Only links whose origins are the
same with the linking resource will be
downloaded.
-s, --stat Print statistics.
-H, --header Add a header to the requests.
--cert= Use the specified client certificate file.
The file must be in PEM format.
--key= Use the client private key file. The file
must be in PEM format.
--no-tls Disable SSL/TLS. Use -2, -3 or --spdy3-1 to
specify SPDY protocol version to use.
-d, --data= Post FILE to server. If - is given, data
will be read from stdin.
-m, --multiply= Request each URI times. By default, same
URI is not requested twice. This option
disables it too.
-p, --proxy= Use this host as a SPDY proxy
-P, --proxy-port=
Use this as the port of the SPDY proxy if
one is set
--color Force colored log output.
$ src/spdycat -nv https://www.google.com/
[ 0.021] NPN select next protocol: the remote server offers:
* spdy/4a4
* spdy/3.1
* spdy/3
* http/1.1
NPN selected the protocol: spdy/3.1
[ 0.029] Handshake complete
[ 0.029] recv SETTINGS frame
(niv=2)
[4(1):100]
[7(0):1048576]
[ 0.029] recv WINDOW_UPDATE frame
(stream_id=0, delta_window_size=983040)
[ 0.029] send SYN_STREAM frame
(stream_id=1, assoc_stream_id=0, pri=3)
:host: www.google.com
:method: GET
:path: /
:scheme: https
:version: HTTP/1.1
accept: */*
accept-encoding: gzip, deflate
user-agent: spdylay/1.2.0-DEV
[ 0.080] recv SYN_REPLY frame
(stream_id=1)
:status: 302 Found
:version: HTTP/1.1
alternate-protocol: 443:quic
cache-control: private
content-length: 262
content-type: text/html; charset=UTF-8
date: Tue, 19 Nov 2013 13:47:18 GMT
location: https://www.google.co.jp/
server: gws
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
[ 0.080] recv DATA frame (stream_id=1, flags=1, length=262)
[ 0.080] send GOAWAY frame
(last_good_stream_id=0)Spdyd - SPDY server +++++++++++++++++++
SPDY server is called spdyd and serves static files. It is single
threaded and multiplexes connections using non-blocking socket. The
static files are read using blocking I/O system call, read(2). It
speaks SPDY/2 and SPDY/3::
$ src/spdyd --htdocs=/your/htdocs/ -v 3000 server.key server.crt
IPv4: listen on port 3000
IPv6: listen on port 3000
The negotiated next protocol: spdy/3.1
[id=1] [ 1.296] send SETTINGS frame
(niv=1)
[4(0):100]
[id=1] [ 1.297] recv SYN_STREAM frame
(stream_id=1, assoc_stream_id=0, pri=3)
:host: localhost:3000
:method: GET
:path: /README
:scheme: https
:version: HTTP/1.1
accept: */*
accept-encoding: gzip, deflate
user-agent: spdylay/1.2.0-DEV
[id=1] [ 1.297] send SYN_REPLY frame
(stream_id=1)
:status: 200 OK
:version: HTTP/1.1
cache-control: max-age=3600
content-length: 66
date: Tue, 19 Nov 2013 14:35:24 GMT
last-modified: Tue, 17 Jan 2012 15:39:01 GMT
server: spdyd spdylay/1.2.0-DEV
[id=1] [ 1.297] send DATA frame (stream_id=1, flags=0, length=66)
[id=1] [ 1.297] send DATA frame (stream_id=1, flags=1, length=0)
[id=1] [ 1.297] stream_id=1 closed
[id=1] [ 1.297] recv GOAWAY frame
(last_good_stream_id=0)
[id=1] [ 1.297] closedCurrently, spdyd needs epoll or kqueue.
Shrpx - A reverse proxy for SPDY/HTTPS ++++++++++++++++++++++++++++++++++++++
For shrpx users who uses shrpx as SPDY proxy: Please consider
migrating to nghttpx developed at nghttp2 project _. nghttpx supports SPDY proxy too.
The shrpx is a multi-threaded reverse proxy for SPDY/HTTPS. It
converts SPDY/HTTPS traffic to plain HTTP. It is initially developed
as a reverse proxy, but now it has other operation modes such as a
frontend forward proxy. For example, with --spdy-proxy (-s in
shorthand) option, it can be used as secure SPDY proxy with a proxy
(e.g., Squid) in the backend. With --cliet-proxy (-p) option,
it acts like an ordinaly forward proxy but expects secure SPDY proxy
in the backend. Thus it becomes an adapter to secure SPDY proxy for
clients which does not support secure SPDY proxy. The another notable
operation mode is --spdy-relay, which just relays SPDY/HTTPS
traffic to the backend in SPDY. The following table summarizes the
operation modes.
================== ========== ======= =============
Mode option Frontend Backend Note
================== ========== ======= =============
default SPDY/HTTPS HTTP Reverse proxy
--spdy SPDY/HTTPS HTTP SPDY proxy
--spdy-relay SPDY/HTTPS SPDY
--client HTTP SPDY
--client-proxy HTTP SPDY Forward proxy
================== ========== ======= =============
The shrpx supports configuration file. See --conf option and
sample configuration file shrpx.conf.sample.
We briefly describe the architecture of shrpx here. It has a
dedicated thread which listens on server sockets. When it accepted
the incoming connection, it passes the file descriptor of the incoming
connection to one of the worker thread. Each worker thread has its
own event
No open issues yet, or sync has not completed.