2012-01-26 17:38:35 +01:00
|
|
|
Spdylay - SPDY C Library
|
|
|
|
========================
|
|
|
|
|
2012-04-25 14:25:51 +02:00
|
|
|
This is an experimental implementation of Google's SPDY protocol in C.
|
|
|
|
|
|
|
|
This library provides SPDY version 2 and 3 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).
|
|
|
|
|
|
|
|
Development Status
|
|
|
|
------------------
|
2012-03-26 16:46:02 +02:00
|
|
|
|
2012-04-05 19:34:55 +02:00
|
|
|
Most of the SPDY/2 and SPDY/3 functionality has been implemented. In
|
|
|
|
both versions, the direct support of server-push has not been
|
2012-03-26 16:46:02 +02:00
|
|
|
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.
|
2012-02-07 18:13:01 +01:00
|
|
|
|
2012-03-29 17:04:08 +02:00
|
|
|
Requirements
|
|
|
|
------------
|
2012-02-07 18:13:01 +01:00
|
|
|
|
2012-03-28 19:33:34 +02:00
|
|
|
The following packages are needed to build the library:
|
|
|
|
|
|
|
|
* pkg-config >= 0.20
|
2012-04-24 19:46:40 +02:00
|
|
|
* zlib >= 1.2.3
|
|
|
|
|
|
|
|
To build and run the unit test programs, the following packages are
|
|
|
|
needed:
|
|
|
|
|
|
|
|
* cunit >= 2.1
|
2012-03-28 19:33:34 +02:00
|
|
|
|
|
|
|
To build and run the example programs, the following packages are
|
|
|
|
needed:
|
|
|
|
|
|
|
|
* OpenSSL >= 1.0.1
|
|
|
|
|
2012-03-29 17:04:08 +02:00
|
|
|
Build from git
|
|
|
|
--------------
|
|
|
|
|
2012-02-07 18:13:01 +01:00
|
|
|
Building from git is easy, but please be sure that at least autoconf 2.68 is
|
|
|
|
used.::
|
|
|
|
|
|
|
|
$ autoreconf -i
|
|
|
|
$ automake
|
|
|
|
$ autoconf
|
|
|
|
$ ./configure
|
|
|
|
$ make
|
|
|
|
|
2012-05-13 09:33:30 +02:00
|
|
|
Building documentation
|
|
|
|
----------------------
|
|
|
|
|
|
|
|
To build documentation, run::
|
|
|
|
|
|
|
|
$ make html
|
|
|
|
|
|
|
|
The documents will be generated under ``doc/manual/html/``.
|
|
|
|
|
|
|
|
The generated documents will not be installed with ``make install``.
|
|
|
|
|
2012-03-10 16:21:00 +01:00
|
|
|
API
|
|
|
|
---
|
|
|
|
|
2012-03-13 16:49:16 +01:00
|
|
|
The public API reference is available on online. Visit
|
|
|
|
http://spdylay.sourceforge.net/. All public APIs are in
|
|
|
|
*spdylay/spdylay.h*. All public API functions as well as the callback
|
|
|
|
function typedefs are documented.
|
2012-03-10 16:21:00 +01:00
|
|
|
|
2012-02-07 18:13:01 +01:00
|
|
|
Examples
|
|
|
|
--------
|
|
|
|
|
|
|
|
*examples* directory contains SPDY client and server implementation
|
|
|
|
using Spdylay. 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
|
|
|
|
<http://technotes.googlecode.com/git/nextprotoneg.html>`_ support is
|
|
|
|
required in order to build and run these programs. At the time of
|
2012-05-09 16:49:11 +02:00
|
|
|
this writing, the OpenSSL 1.0.1 supports NPN.
|
2012-02-07 18:13:01 +01:00
|
|
|
|
2012-05-13 10:13:36 +02:00
|
|
|
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::
|
|
|
|
|
|
|
|
$ examples/spdycat -h
|
|
|
|
Usage: spdycat [-Onv23] [-t <SECONDS>] [-w <WINDOW_BITS>] [--cert=<CERT>]
|
|
|
|
[--key=<KEY>] <URI>...
|
|
|
|
|
|
|
|
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.
|
|
|
|
-t, --timeout=<N> Timeout each request after <N> seconds.
|
|
|
|
-w, --window-bits=<N>
|
|
|
|
Sets the initial window size to 2**<N>.
|
|
|
|
--cert=<CERT> Use the specified client certificate file.
|
|
|
|
The file must be in PEM format.
|
|
|
|
--key=<KEY> Use the client private key file. The file
|
|
|
|
must be in PEM format.
|
|
|
|
$ examples/spdycat -nv https://www.google.com/
|
|
|
|
[ 0.025] NPN select next protocol: the remote server offers:
|
|
|
|
* spdy/3
|
2012-02-01 16:45:02 +01:00
|
|
|
* spdy/2
|
|
|
|
* http/1.1
|
2012-05-13 10:13:36 +02:00
|
|
|
NPN selected the protocol: spdy/3
|
|
|
|
[ 0.035] recv SETTINGS frame <version=3, flags=0, length=20>
|
|
|
|
(niv=2)
|
2012-02-01 16:45:02 +01:00
|
|
|
[4(1):100]
|
2012-05-13 10:13:36 +02:00
|
|
|
[7(0):12288]
|
|
|
|
[ 0.035] send SYN_STREAM frame <version=3, flags=1, length=106>
|
2012-02-01 16:45:02 +01:00
|
|
|
(stream_id=1, assoc_stream_id=0, pri=3)
|
2012-05-13 10:13:36 +02:00
|
|
|
:host: www.google.com
|
|
|
|
:method: GET
|
|
|
|
:path: /
|
|
|
|
:scheme: https
|
|
|
|
:version: HTTP/1.1
|
|
|
|
accept: */*
|
|
|
|
user-agent: spdylay/0.2.0
|
|
|
|
[ 0.077] recv SYN_REPLY frame <version=3, flags=0, length=558>
|
2012-02-01 16:45:02 +01:00
|
|
|
(stream_id=1)
|
2012-05-13 10:13:36 +02:00
|
|
|
:status: 302 Found
|
|
|
|
:version: HTTP/1.1
|
|
|
|
cache-control: private
|
|
|
|
content-length: 222
|
|
|
|
content-type: text/html; charset=UTF-8
|
|
|
|
date: Sun, 13 May 2012 08:02:54 GMT
|
|
|
|
location: https://www.google.co.jp/
|
2012-02-01 16:45:02 +01:00
|
|
|
server: gws
|
|
|
|
x-frame-options: SAMEORIGIN
|
|
|
|
x-xss-protection: 1; mode=block
|
2012-05-13 10:13:36 +02:00
|
|
|
[ 0.077] recv DATA frame (stream_id=1, flags=1, length=222)
|
|
|
|
[ 0.077] send GOAWAY frame <version=3, flags=0, length=8>
|
2012-02-01 16:45:02 +01:00
|
|
|
(last_good_stream_id=0)
|
2012-01-31 18:39:04 +01:00
|
|
|
|
2012-05-13 10:13:36 +02:00
|
|
|
SPDY server is called ``spdyd``. It is a non-blocking server and only
|
|
|
|
serves static contents. It can speak SPDY/2 and SPDY/3::
|
2012-02-26 10:25:59 +01:00
|
|
|
|
2012-05-13 10:13:36 +02:00
|
|
|
$ examples/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
|
|
|
|
[id=1] [ 17.456] send SETTINGS frame <version=3, flags=0, length=12>
|
|
|
|
(niv=1)
|
|
|
|
[4(0):100]
|
|
|
|
[id=1] [ 17.457] recv SYN_STREAM frame <version=3, flags=1, length=108>
|
2012-02-26 10:25:59 +01:00
|
|
|
(stream_id=1, assoc_stream_id=0, pri=3)
|
|
|
|
:host: localhost:3000
|
|
|
|
:method: GET
|
2012-05-13 10:13:36 +02:00
|
|
|
:path: /README
|
2012-02-26 10:25:59 +01:00
|
|
|
:scheme: https
|
|
|
|
:version: HTTP/1.1
|
2012-05-13 10:13:36 +02:00
|
|
|
accept: */*
|
|
|
|
user-agent: spdylay/0.2.0
|
|
|
|
[id=1] [ 17.457] send SYN_REPLY frame <version=3, flags=0, length=113>
|
2012-02-26 10:25:59 +01:00
|
|
|
(stream_id=1)
|
2012-05-13 10:13:36 +02:00
|
|
|
:status: 200 OK
|
2012-02-26 10:25:59 +01:00
|
|
|
:version: HTTP/1.1
|
|
|
|
cache-control: max-age=3600
|
2012-05-13 10:13:36 +02:00
|
|
|
content-length: 15
|
|
|
|
date: Sun, 13 May 2012 08:06:12 GMT
|
|
|
|
last-modified: Tue, 17 Jan 2012 15:39:01 GMT
|
|
|
|
server: spdyd spdylay/0.2.0
|
|
|
|
[id=1] [ 17.467] send DATA frame (stream_id=1, flags=0, length=15)
|
|
|
|
[id=1] [ 17.467] send DATA frame (stream_id=1, flags=1, length=0)
|
|
|
|
[id=1] [ 17.468] stream_id=1 closed
|
|
|
|
[id=1] [ 17.468] recv GOAWAY frame <version=3, flags=0, length=8>
|
2012-02-07 18:13:01 +01:00
|
|
|
(last_good_stream_id=0)
|
2012-05-13 10:13:36 +02:00
|
|
|
[id=1] [ 17.468] closed
|
2012-01-31 19:09:42 +01:00
|
|
|
|
2012-02-09 18:29:41 +01:00
|
|
|
Currently, ``spdyd`` needs ``epoll`` or ``kqueue``.
|
2012-02-14 16:04:16 +01:00
|
|
|
|
|
|
|
There is another SPDY server called ``spdynative``, which is
|
|
|
|
`node.native <https://github.com/d5/node.native>`_ style simple SPDY
|
|
|
|
server::
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include "spdy.h"
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
spdy server;
|
|
|
|
if(!server.listen("localhost", 8080, "server.key", "server.crt",
|
|
|
|
[](request& req, response& res) {
|
|
|
|
res.set_status(200);
|
|
|
|
res.set_header("content-type", "text/plain");
|
|
|
|
res.end("C++ FTW\n");
|
|
|
|
}))
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
|
|
|
std::cout << "Server running at http://localhost:8080/" << std::endl;
|
|
|
|
return reactor::run(server);
|
|
|
|
}
|
|
|
|
|
|
|
|
Don't expect much from ``spdynative``. It is just an example and does
|
|
|
|
not support asynchronous I/O at all.
|
2012-05-13 10:13:36 +02:00
|
|
|
|
|
|
|
If you are looking for the example program written in C, see
|
|
|
|
``spdycli`` which is the simple SPDY client.
|