| 1 |
= File server example with directory listing |
| 2 |
|
| 3 |
To try this example, you need GNU `make` and `git` in your PATH. |
| 4 |
|
| 5 |
To build and run the example, use the following command: |
| 6 |
|
| 7 |
[source,bash] |
| 8 |
$ make run |
| 9 |
|
| 10 |
Then point your browser to http://localhost:8080 |
| 11 |
to browse the contents of the `priv` directory. |
| 12 |
|
| 13 |
Interesting examples include: |
| 14 |
|
| 15 |
* http://localhost:8080/test.txt[Plain text file] |
| 16 |
* http://localhost:8080/video.html[HTML5 video demo] |
| 17 |
|
| 18 |
== HTTP/1.1 example output |
| 19 |
|
| 20 |
[source,bash] |
| 21 |
---- |
| 22 |
$ curl -i http://localhost:8080/test.txt |
| 23 |
HTTP/1.1 200 OK |
| 24 |
connection: keep-alive |
| 25 |
server: Cowboy |
| 26 |
date: Mon, 09 Sep 2013 13:49:50 GMT |
| 27 |
content-length: 52 |
| 28 |
content-type: text/plain |
| 29 |
last-modified: Fri, 18 Jan 2013 16:33:31 GMT |
| 30 |
|
| 31 |
If you read this then the static file server works! |
| 32 |
---- |
| 33 |
|
| 34 |
== HTTP/2 example output |
| 35 |
|
| 36 |
[source,bash] |
| 37 |
---- |
| 38 |
$ nghttp -v http://localhost:8080/test.txt |
| 39 |
[ 0.000] Connected |
| 40 |
[ 0.000] send SETTINGS frame <length=12, flags=0x00, stream_id=0> |
| 41 |
(niv=2) |
| 42 |
[SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100] |
| 43 |
[SETTINGS_INITIAL_WINDOW_SIZE(0x04):65535] |
| 44 |
[ 0.000] send PRIORITY frame <length=5, flags=0x00, stream_id=3> |
| 45 |
(dep_stream_id=0, weight=201, exclusive=0) |
| 46 |
[ 0.000] send PRIORITY frame <length=5, flags=0x00, stream_id=5> |
| 47 |
(dep_stream_id=0, weight=101, exclusive=0) |
| 48 |
[ 0.000] send PRIORITY frame <length=5, flags=0x00, stream_id=7> |
| 49 |
(dep_stream_id=0, weight=1, exclusive=0) |
| 50 |
[ 0.000] send PRIORITY frame <length=5, flags=0x00, stream_id=9> |
| 51 |
(dep_stream_id=7, weight=1, exclusive=0) |
| 52 |
[ 0.000] send PRIORITY frame <length=5, flags=0x00, stream_id=11> |
| 53 |
(dep_stream_id=3, weight=1, exclusive=0) |
| 54 |
[ 0.000] send HEADERS frame <length=46, flags=0x25, stream_id=13> |
| 55 |
; END_STREAM | END_HEADERS | PRIORITY |
| 56 |
(padlen=0, dep_stream_id=11, weight=16, exclusive=0) |
| 57 |
; Open new stream |
| 58 |
:method: GET |
| 59 |
:path: /test.txt |
| 60 |
:scheme: http |
| 61 |
:authority: localhost:8080 |
| 62 |
accept: */* |
| 63 |
accept-encoding: gzip, deflate |
| 64 |
user-agent: nghttp2/1.7.1 |
| 65 |
[ 0.001] recv SETTINGS frame <length=0, flags=0x00, stream_id=0> |
| 66 |
(niv=0) |
| 67 |
[ 0.001] recv SETTINGS frame <length=0, flags=0x01, stream_id=0> |
| 68 |
; ACK |
| 69 |
(niv=0) |
| 70 |
[ 0.001] send SETTINGS frame <length=0, flags=0x01, stream_id=0> |
| 71 |
; ACK |
| 72 |
(niv=0) |
| 73 |
[ 0.007] recv (stream_id=13) :status: 200 |
| 74 |
[ 0.007] recv (stream_id=13) content-length: 52 |
| 75 |
[ 0.007] recv (stream_id=13) content-type: text/plain |
| 76 |
[ 0.007] recv (stream_id=13) date: Mon, 13 Jun 2016 11:25:20 GMT |
| 77 |
[ 0.007] recv (stream_id=13) etag: "1371478245" |
| 78 |
[ 0.007] recv (stream_id=13) last-modified: Tue, 12 Aug 2014 17:00:17 GMT |
| 79 |
[ 0.007] recv (stream_id=13) server: Cowboy |
| 80 |
[ 0.007] recv HEADERS frame <length=81, flags=0x04, stream_id=13> |
| 81 |
; END_HEADERS |
| 82 |
(padlen=0) |
| 83 |
; First response header |
| 84 |
If you read this then the static file server works! |
| 85 |
[ 0.007] recv DATA frame <length=52, flags=0x01, stream_id=13> |
| 86 |
; END_STREAM |
| 87 |
[ 0.007] send GOAWAY frame <length=8, flags=0x00, stream_id=0> |
| 88 |
(last_stream_id=0, error_code=NO_ERROR(0x00), opaque_data(0)=[]) |
| 89 |
---- |