| 1 |
= Secure hello world example |
| 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 https://localhost:8443 |
| 11 |
|
| 12 |
You will be greeted by a security message. You can ask for more |
| 13 |
information and ultimately accept to access localhost. This is |
| 14 |
due to the example using a self-signed certificate. |
| 15 |
|
| 16 |
Recent browsers will communicate using HTTP/2. Older browsers |
| 17 |
will use HTTP/1.1. |
| 18 |
|
| 19 |
== HTTP/1.1 example output |
| 20 |
|
| 21 |
[source,bash] |
| 22 |
---- |
| 23 |
$ curl -k -i https://localhost:8443 |
| 24 |
HTTP/1.1 200 OK |
| 25 |
connection: keep-alive |
| 26 |
server: Cowboy |
| 27 |
date: Fri, 28 Sep 2012 04:10:25 GMT |
| 28 |
content-length: 12 |
| 29 |
|
| 30 |
Hello world! |
| 31 |
---- |
| 32 |
|
| 33 |
== HTTP/2 example output |
| 34 |
|
| 35 |
[source,bash] |
| 36 |
---- |
| 37 |
$ nghttp -v https://localhost:8443 |
| 38 |
[ 0.001] Connected |
| 39 |
The negotiated protocol: h2 |
| 40 |
[ 0.009] recv SETTINGS frame <length=0, flags=0x00, stream_id=0> |
| 41 |
(niv=0) |
| 42 |
[ 0.009] send SETTINGS frame <length=12, flags=0x00, stream_id=0> |
| 43 |
(niv=2) |
| 44 |
[SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100] |
| 45 |
[SETTINGS_INITIAL_WINDOW_SIZE(0x04):65535] |
| 46 |
[ 0.009] send SETTINGS frame <length=0, flags=0x01, stream_id=0> |
| 47 |
; ACK |
| 48 |
(niv=0) |
| 49 |
[ 0.009] send PRIORITY frame <length=5, flags=0x00, stream_id=3> |
| 50 |
(dep_stream_id=0, weight=201, exclusive=0) |
| 51 |
[ 0.009] send PRIORITY frame <length=5, flags=0x00, stream_id=5> |
| 52 |
(dep_stream_id=0, weight=101, exclusive=0) |
| 53 |
[ 0.009] send PRIORITY frame <length=5, flags=0x00, stream_id=7> |
| 54 |
(dep_stream_id=0, weight=1, exclusive=0) |
| 55 |
[ 0.009] send PRIORITY frame <length=5, flags=0x00, stream_id=9> |
| 56 |
(dep_stream_id=7, weight=1, exclusive=0) |
| 57 |
[ 0.009] send PRIORITY frame <length=5, flags=0x00, stream_id=11> |
| 58 |
(dep_stream_id=3, weight=1, exclusive=0) |
| 59 |
[ 0.009] send HEADERS frame <length=38, flags=0x25, stream_id=13> |
| 60 |
; END_STREAM | END_HEADERS | PRIORITY |
| 61 |
(padlen=0, dep_stream_id=11, weight=16, exclusive=0) |
| 62 |
; Open new stream |
| 63 |
:method: GET |
| 64 |
:path: / |
| 65 |
:scheme: https |
| 66 |
:authority: localhost:8443 |
| 67 |
accept: */* |
| 68 |
accept-encoding: gzip, deflate |
| 69 |
user-agent: nghttp2/1.7.1 |
| 70 |
[ 0.010] recv SETTINGS frame <length=0, flags=0x01, stream_id=0> |
| 71 |
; ACK |
| 72 |
(niv=0) |
| 73 |
[ 0.010] recv (stream_id=13) :status: 200 |
| 74 |
[ 0.010] recv (stream_id=13) content-length: 12 |
| 75 |
[ 0.010] recv (stream_id=13) content-type: text/plain |
| 76 |
[ 0.010] recv (stream_id=13) date: Sat, 30 Apr 2016 12:54:32 GMT |
| 77 |
[ 0.010] recv (stream_id=13) server: Cowboy |
| 78 |
[ 0.010] recv HEADERS frame <length=45, flags=0x04, stream_id=13> |
| 79 |
; END_HEADERS |
| 80 |
(padlen=0) |
| 81 |
; First response header |
| 82 |
Hello world![ 0.010] recv DATA frame <length=12, flags=0x01, stream_id=13> |
| 83 |
; END_STREAM |
| 84 |
[ 0.010] send GOAWAY frame <length=8, flags=0x00, stream_id=0> |
| 85 |
(last_stream_id=0, error_code=NO_ERROR(0x00), opaque_data(0)=[]) |
| 86 |
---- |