| 1 |
= Basic authorization example using REST |
| 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 |
|
| 12 |
== HTTP/1.1 example output |
| 13 |
|
| 14 |
Request with no authentication: |
| 15 |
|
| 16 |
[source,bash] |
| 17 |
---- |
| 18 |
$ curl -i http://localhost:8080 |
| 19 |
HTTP/1.1 401 Unauthorized |
| 20 |
connection: keep-alive |
| 21 |
server: Cowboy |
| 22 |
date: Sun, 20 Jan 2013 14:10:27 GMT |
| 23 |
content-length: 0 |
| 24 |
www-authenticate: Basic realm="cowboy" |
| 25 |
---- |
| 26 |
|
| 27 |
Request with authentication: |
| 28 |
|
| 29 |
[source,bash] |
| 30 |
---- |
| 31 |
$ curl -i -u "Alladin:open sesame" http://localhost:8080 |
| 32 |
HTTP/1.1 200 OK |
| 33 |
connection: keep-alive |
| 34 |
server: Cowboy |
| 35 |
date: Sun, 20 Jan 2013 14:11:12 GMT |
| 36 |
content-length: 16 |
| 37 |
content-type: text/plain |
| 38 |
|
| 39 |
Hello, Alladin! |
| 40 |
---- |
| 41 |
|
| 42 |
== HTTP/2 example output |
| 43 |
|
| 44 |
Request with no authentication: |
| 45 |
|
| 46 |
[source,bash] |
| 47 |
---- |
| 48 |
$ nghttp -v http://localhost:8080 |
| 49 |
[ 0.000] Connected |
| 50 |
[ 0.000] send SETTINGS frame <length=12, flags=0x00, stream_id=0> |
| 51 |
(niv=2) |
| 52 |
[SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100] |
| 53 |
[SETTINGS_INITIAL_WINDOW_SIZE(0x04):65535] |
| 54 |
[ 0.000] send PRIORITY frame <length=5, flags=0x00, stream_id=3> |
| 55 |
(dep_stream_id=0, weight=201, exclusive=0) |
| 56 |
[ 0.000] send PRIORITY frame <length=5, flags=0x00, stream_id=5> |
| 57 |
(dep_stream_id=0, weight=101, exclusive=0) |
| 58 |
[ 0.000] send PRIORITY frame <length=5, flags=0x00, stream_id=7> |
| 59 |
(dep_stream_id=0, weight=1, exclusive=0) |
| 60 |
[ 0.000] send PRIORITY frame <length=5, flags=0x00, stream_id=9> |
| 61 |
(dep_stream_id=7, weight=1, exclusive=0) |
| 62 |
[ 0.000] send PRIORITY frame <length=5, flags=0x00, stream_id=11> |
| 63 |
(dep_stream_id=3, weight=1, exclusive=0) |
| 64 |
[ 0.000] send HEADERS frame <length=38, flags=0x25, stream_id=13> |
| 65 |
; END_STREAM | END_HEADERS | PRIORITY |
| 66 |
(padlen=0, dep_stream_id=11, weight=16, exclusive=0) |
| 67 |
; Open new stream |
| 68 |
:method: GET |
| 69 |
:path: / |
| 70 |
:scheme: http |
| 71 |
:authority: localhost:8080 |
| 72 |
accept: */* |
| 73 |
accept-encoding: gzip, deflate |
| 74 |
user-agent: nghttp2/1.7.1 |
| 75 |
[ 0.004] recv SETTINGS frame <length=0, flags=0x00, stream_id=0> |
| 76 |
(niv=0) |
| 77 |
[ 0.004] recv SETTINGS frame <length=0, flags=0x01, stream_id=0> |
| 78 |
; ACK |
| 79 |
(niv=0) |
| 80 |
[ 0.004] send SETTINGS frame <length=0, flags=0x01, stream_id=0> |
| 81 |
; ACK |
| 82 |
(niv=0) |
| 83 |
[ 0.004] recv (stream_id=13) :status: 401 |
| 84 |
[ 0.004] recv (stream_id=13) content-length: 0 |
| 85 |
[ 0.004] recv (stream_id=13) date: Tue, 14 Jun 2016 09:15:56 GMT |
| 86 |
[ 0.004] recv (stream_id=13) server: Cowboy |
| 87 |
[ 0.004] recv (stream_id=13) www-authenticate: Basic realm="cowboy" |
| 88 |
[ 0.004] recv HEADERS frame <length=56, flags=0x04, stream_id=13> |
| 89 |
; END_HEADERS |
| 90 |
(padlen=0) |
| 91 |
; First response header |
| 92 |
[ 0.004] recv DATA frame <length=0, flags=0x01, stream_id=13> |
| 93 |
; END_STREAM |
| 94 |
[ 0.004] send GOAWAY frame <length=8, flags=0x00, stream_id=0> |
| 95 |
(last_stream_id=0, error_code=NO_ERROR(0x00), opaque_data(0)=[]) |
| 96 |
---- |
| 97 |
|
| 98 |
Request with authentication: |
| 99 |
|
| 100 |
[source,bash] |
| 101 |
---- |
| 102 |
$ nghttp -v -H "Authorization: Basic `echo -n Alladin:open sesame | base64`" http://localhost:8080 |
| 103 |
[ 0.000] Connected |
| 104 |
[ 0.000] send SETTINGS frame <length=12, flags=0x00, stream_id=0> |
| 105 |
(niv=2) |
| 106 |
[SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100] |
| 107 |
[SETTINGS_INITIAL_WINDOW_SIZE(0x04):65535] |
| 108 |
[ 0.000] send PRIORITY frame <length=5, flags=0x00, stream_id=3> |
| 109 |
(dep_stream_id=0, weight=201, exclusive=0) |
| 110 |
[ 0.000] send PRIORITY frame <length=5, flags=0x00, stream_id=5> |
| 111 |
(dep_stream_id=0, weight=101, exclusive=0) |
| 112 |
[ 0.000] send PRIORITY frame <length=5, flags=0x00, stream_id=7> |
| 113 |
(dep_stream_id=0, weight=1, exclusive=0) |
| 114 |
[ 0.000] send PRIORITY frame <length=5, flags=0x00, stream_id=9> |
| 115 |
(dep_stream_id=7, weight=1, exclusive=0) |
| 116 |
[ 0.001] send PRIORITY frame <length=5, flags=0x00, stream_id=11> |
| 117 |
(dep_stream_id=3, weight=1, exclusive=0) |
| 118 |
[ 0.001] send HEADERS frame <length=68, flags=0x25, stream_id=13> |
| 119 |
; END_STREAM | END_HEADERS | PRIORITY |
| 120 |
(padlen=0, dep_stream_id=11, weight=16, exclusive=0) |
| 121 |
; Open new stream |
| 122 |
:method: GET |
| 123 |
:path: / |
| 124 |
:scheme: http |
| 125 |
:authority: localhost:8080 |
| 126 |
accept: */* |
| 127 |
accept-encoding: gzip, deflate |
| 128 |
user-agent: nghttp2/1.7.1 |
| 129 |
authorization: Basic QWxsYWRpbjpvcGVuIHNlc2FtZQ== |
| 130 |
[ 0.002] recv SETTINGS frame <length=0, flags=0x00, stream_id=0> |
| 131 |
(niv=0) |
| 132 |
[ 0.002] recv SETTINGS frame <length=0, flags=0x01, stream_id=0> |
| 133 |
; ACK |
| 134 |
(niv=0) |
| 135 |
[ 0.002] send SETTINGS frame <length=0, flags=0x01, stream_id=0> |
| 136 |
; ACK |
| 137 |
(niv=0) |
| 138 |
[ 0.004] recv (stream_id=13) :status: 200 |
| 139 |
[ 0.004] recv (stream_id=13) content-length: 16 |
| 140 |
[ 0.004] recv (stream_id=13) content-type: text/plain |
| 141 |
[ 0.004] recv (stream_id=13) date: Tue, 14 Jun 2016 09:15:48 GMT |
| 142 |
[ 0.004] recv (stream_id=13) server: Cowboy |
| 143 |
[ 0.004] recv HEADERS frame <length=45, flags=0x04, stream_id=13> |
| 144 |
; END_HEADERS |
| 145 |
(padlen=0) |
| 146 |
; First response header |
| 147 |
Hello, Alladin! |
| 148 |
[ 0.004] recv DATA frame <length=16, flags=0x01, stream_id=13> |
| 149 |
; END_STREAM |
| 150 |
[ 0.004] send GOAWAY frame <length=8, flags=0x00, stream_id=0> |
| 151 |
(last_stream_id=0, error_code=NO_ERROR(0x00), opaque_data(0)=[]) |
| 152 |
---- |