README.asciidoc 5.3 KB

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