diff --git a/examples/chunked_hello_world/README.md b/examples/chunked_hello_world/README.asciidoc similarity index 50% rename from examples/chunked_hello_world/README.md rename to examples/chunked_hello_world/README.asciidoc index c568e3bf..4b4225da 100644 --- a/examples/chunked_hello_world/README.md +++ b/examples/chunked_hello_world/README.asciidoc @@ -1,27 +1,19 @@ -Chunked hello world example -=========================== += Chunked hello world example To try this example, you need GNU `make` and `git` in your PATH. -To build the example, run the following command: +To build and run the example, use the following command: -``` bash -$ make -``` +[source,bash] +$ make run -To start the release in the foreground: - -``` bash -$ ./_rel/chunked_hello_world_example/bin/chunked_hello_world_example console -``` - -Then point your browser at [http://localhost:8080](http://localhost:8080), +Then point your browser to http://localhost:8080 or use `curl` to see the chunks arriving one at a time every second. -Example output --------------- +== Example output -``` bash +[source,bash] +---- $ time curl -i http://localhost:8080 HTTP/1.1 200 OK transfer-encoding: chunked @@ -33,4 +25,4 @@ Hello World Chunked! curl -i http://localhost:8080 0.01s user 0.00s system 0% cpu 2.015 total -``` +---- diff --git a/examples/compress_response/README.md b/examples/compress_response/README.asciidoc similarity index 85% rename from examples/compress_response/README.md rename to examples/compress_response/README.asciidoc index ecffcad6..1e6d2ed4 100644 --- a/examples/compress_response/README.md +++ b/examples/compress_response/README.asciidoc @@ -1,28 +1,20 @@ -Compressed response example -=========================== += Compressed response example To try this example, you need GNU `make` and `git` in your PATH. -To build the example, run the following command: +To build and run the example, use the following command: -``` bash -$ make -``` +[source,bash] +$ make run -To start the release in the foreground: +Then point your browser to http://localhost:8080 -``` bash -$ ./_rel/compress_response_example/bin/compress_response_example console -``` - -Then point your browser at [http://localhost:8080](http://localhost:8080). - -Example output --------------- +== Example output Without compression: -``` bash +[source,bash] +---- $ curl -i http://localhost:8080 HTTP/1.1 200 OK connection: keep-alive @@ -42,11 +34,12 @@ have established the ability to work at virtually identical tasks and obtained considerable respect for their achievements. There are also cattle handlers in many other parts of the world, particularly South America and Australia, who perform work similar to the cowboy in their respective nations. -``` +---- With compression: -``` +[source,bash] +---- $ curl -i --compressed http://localhost:8080 HTTP/1.1 200 OK connection: keep-alive @@ -67,4 +60,4 @@ have established the ability to work at virtually identical tasks and obtained considerable respect for their achievements. There are also cattle handlers in many other parts of the world, particularly South America and Australia, who perform work similar to the cowboy in their respective nations. -``` +---- diff --git a/examples/cookie/README.asciidoc b/examples/cookie/README.asciidoc new file mode 100644 index 00000000..20294f53 --- /dev/null +++ b/examples/cookie/README.asciidoc @@ -0,0 +1,13 @@ += Cookie example + +To try this example, you need GNU `make` and `git` in your PATH. + +To build and run the example, use the following command: + +[source,bash] +$ make run + +Then point your browser to http://localhost:8080 + +This example allows you to use any path to show that the cookies +are defined site-wide. Try it! diff --git a/examples/cookie/README.md b/examples/cookie/README.md deleted file mode 100644 index 61ddaaed..00000000 --- a/examples/cookie/README.md +++ /dev/null @@ -1,20 +0,0 @@ -Cookie example -============== - -To try this example, you need GNU `make` and `git` in your PATH. - -To build the example, run the following command: - -``` bash -$ make -``` - -To start the release in the foreground: - -``` bash -$ ./_rel/cookie_example/bin/cookie_example console -``` - -Then point your browser at [http://localhost:8080](http://localhost:8080). -This example allows you to use any path to show that the cookies -are defined site-wide. Try it! diff --git a/examples/echo_get/README.md b/examples/echo_get/README.asciidoc similarity index 50% rename from examples/echo_get/README.md rename to examples/echo_get/README.asciidoc index 737d04d0..d002d612 100644 --- a/examples/echo_get/README.md +++ b/examples/echo_get/README.asciidoc @@ -1,29 +1,21 @@ -GET parameter echo example -========================== += GET parameter echo example To try this example, you need GNU `make` and `git` in your PATH. -To build the example, run the following command: +To build and run the example, use the following command: -``` bash -$ make -``` +[source,bash] +$ make run -To start the release in the foreground: +Then point your browser to http://localhost:8080/?echo=hello -``` bash -$ ./_rel/echo_get_example/bin/echo_get_example console -``` - -Then point your browser at -[http://localhost:8080/?echo=hello](http://localhost:8080/?echo=hello). You can replace the `echo` parameter with another to check that the handler is echoing it back properly. -Example output --------------- +== Example output -``` bash +[source,bash] +---- $ curl -i "http://localhost:8080/?echo=saymyname" HTTP/1.1 200 OK connection: keep-alive @@ -33,4 +25,4 @@ content-length: 9 content-type: text/plain; charset=utf-8 saymyname -``` +---- diff --git a/examples/echo_post/README.md b/examples/echo_post/README.asciidoc similarity index 64% rename from examples/echo_post/README.md rename to examples/echo_post/README.asciidoc index cc89fd60..144e2167 100644 --- a/examples/echo_post/README.md +++ b/examples/echo_post/README.asciidoc @@ -1,29 +1,21 @@ -POST parameter echo example -=========================== += POST parameter echo example To try this example, you need GNU `make` and `git` in your PATH. -To build the example, run the following command: +To build and run the example, use the following command: -``` bash -$ make -``` - -To start the release in the foreground: - -``` bash -$ ./_rel/echo_post_example/bin/echo_post_example console -``` +[source,bash] +$ make run As this example echoes a POST parameter, it is a little more complex to test. Some browsers feature tools that allow you to perform one such request, or you can use the command line tool `curl` as we will demonstrate. -Example output --------------- +== Example output -``` bash +[source,bash] +---- $ curl -i -d echo=echomeplz http://localhost:8080 HTTP/1.1 200 OK connection: keep-alive @@ -33,4 +25,4 @@ content-length: 9 content-type: text/plain; charset=utf-8 echomeplz -``` +---- diff --git a/examples/error_hook/README.md b/examples/error_hook/README.asciidoc similarity index 63% rename from examples/error_hook/README.md rename to examples/error_hook/README.asciidoc index cd0da97a..6f61cb71 100644 --- a/examples/error_hook/README.md +++ b/examples/error_hook/README.asciidoc @@ -1,28 +1,20 @@ -Error hook example -================== += Error hook example To try this example, you need GNU `make` and `git` in your PATH. -To build the example, run the following command: +To build and run the example, use the following command: -``` bash -$ make -``` +[source,bash] +$ make run -To start the release in the foreground: +Then point your browser to http://localhost:8080 -``` bash -$ ./_rel/error_hook_example/bin/error_hook_example console -``` - -Then point your browser at [http://localhost:8080](http://localhost:8080). - -Example output --------------- +== Example output Not found: -``` bash +[source,bash] +---- $ curl -i http://localhost:8080 HTTP/1.1 404 Not Found connection: keep-alive @@ -31,11 +23,12 @@ date: Wed, 27 Feb 2013 23:32:55 GMT content-length: 56 404 Not Found: "/" is not the path you are looking for. -``` +---- Bad request: -``` bash +[source,bash] +---- $ telnet localhost 8080 Trying ::1... Connection failed: Connection refused @@ -51,4 +44,4 @@ content-length: 15 HTTP Error 400 Connection closed by foreign host. -``` +---- diff --git a/examples/eventsource/README.asciidoc b/examples/eventsource/README.asciidoc new file mode 100644 index 00000000..9461b776 --- /dev/null +++ b/examples/eventsource/README.asciidoc @@ -0,0 +1,10 @@ += EventSource example + +To try this example, you need GNU `make` and `git` in your PATH. + +To build and run the example, use the following command: + +[source,bash] +$ make run + +Then point your browser to http://localhost:8080 diff --git a/examples/eventsource/README.md b/examples/eventsource/README.md deleted file mode 100644 index b6b611cf..00000000 --- a/examples/eventsource/README.md +++ /dev/null @@ -1,19 +0,0 @@ -EventSource example -=================== - -To try this example, you need GNU `make` and `git` in your PATH. - -To build the example, run the following command: - -``` bash -$ make -``` - -To start the release in the foreground: - -``` bash -$ ./_rel/eventsource_example/bin/eventsource_example console -``` - -Then point your EventSource capable browser at -[http://localhost:8080](http://localhost:8080). diff --git a/examples/hello_world/README.asciidoc b/examples/hello_world/README.asciidoc new file mode 100644 index 00000000..66a6bd69 --- /dev/null +++ b/examples/hello_world/README.asciidoc @@ -0,0 +1,25 @@ += Hello world example + +To try this example, you need GNU `make` and `git` in your PATH. + +To build and run the example, use the following command: + +[source,bash] +$ make run + +Then point your browser to http://localhost:8080 + +== Example output + +[source,bash] +---- +$ curl -i http://localhost:8080 +HTTP/1.1 200 OK +connection: keep-alive +server: Cowboy +date: Fri, 28 Sep 2012 04:10:25 GMT +content-length: 12 +content-type: text/plain + +Hello world! +---- diff --git a/examples/hello_world/README.md b/examples/hello_world/README.md deleted file mode 100644 index 1e5be0e9..00000000 --- a/examples/hello_world/README.md +++ /dev/null @@ -1,33 +0,0 @@ -Hello world example -=================== - -To try this example, you need GNU `make` and `git` in your PATH. - -To build the example, run the following command: - -``` bash -$ make -``` - -To start the release in the foreground: - -``` bash -$ ./_rel/hello_world_example/bin/hello_world_example console -``` - -Then point your browser at [http://localhost:8080](http://localhost:8080). - -Example output --------------- - -``` bash -$ curl -i http://localhost:8080 -HTTP/1.1 200 OK -connection: keep-alive -server: Cowboy -date: Fri, 28 Sep 2012 04:10:25 GMT -content-length: 12 -content-type: text/plain - -Hello world! -``` diff --git a/examples/markdown_middleware/README.asciidoc b/examples/markdown_middleware/README.asciidoc new file mode 100644 index 00000000..3881bfb9 --- /dev/null +++ b/examples/markdown_middleware/README.asciidoc @@ -0,0 +1,15 @@ += Middleware example + +To try this example, you need GNU `make` and `git` in your PATH. + +To build and run the example, use the following command: + +[source,bash] +$ make run + +Then point your browser to http://localhost:8080/video.html + +Cowboy will serve all the files you put in the `priv` directory. +If you request a `.html` file that has a corresponding `.md` file +that has been modified more recently than the `.html` file, the +Markdown file will be converted to HTML and served by Cowboy. diff --git a/examples/markdown_middleware/README.md b/examples/markdown_middleware/README.md deleted file mode 100644 index cc890fce..00000000 --- a/examples/markdown_middleware/README.md +++ /dev/null @@ -1,24 +0,0 @@ -Middleware example -================== - -To try this example, you need GNU `make` and `git` in your PATH. - -To build the example, run the following command: - -``` bash -$ make -``` - -To start the release in the foreground: - -``` bash -$ ./_rel/markdown_middleware_example/bin/markdown_middleware_example console -``` - -Then point your browser at -[http://localhost:8080/video.html](http://localhost:8080/video.html). - -Cowboy will serve all the files you put in the `priv` directory. -If you request a `.html` file that has a corresponding `.md` file -that has been modified more recently than the `.html` file, the -Markdown file will be converted to HTML and served by Cowboy. diff --git a/examples/rest_basic_auth/README.md b/examples/rest_basic_auth/README.asciidoc similarity index 56% rename from examples/rest_basic_auth/README.md rename to examples/rest_basic_auth/README.asciidoc index 236ce2fd..04609b3d 100644 --- a/examples/rest_basic_auth/README.md +++ b/examples/rest_basic_auth/README.asciidoc @@ -1,28 +1,20 @@ -Basic authorization example using REST -====================================== += Basic authorization example using REST To try this example, you need GNU `make` and `git` in your PATH. -To build the example, run the following command: +To build and run the example, use the following command: -``` bash -$ make -``` +[source,bash] +$ make run -To start the release in the foreground: +Then point your browser to http://localhost:8080 -``` bash -$ ./_rel/rest_basic_auth_example/bin/rest_basic_auth_example console -``` - -Then point your browser at [http://localhost:8080](http://localhost:8080). - -Example output --------------- +== Example output Request with no authentication: -``` bash +[source,bash] +---- $ curl -i http://localhost:8080 HTTP/1.1 401 Unauthorized connection: keep-alive @@ -30,11 +22,12 @@ server: Cowboy date: Sun, 20 Jan 2013 14:10:27 GMT content-length: 0 www-authenticate: Basic realm="cowboy" -``` +---- Request with authentication: -``` bash +[source,bash] +---- $ curl -i -u "Alladin:open sesame" http://localhost:8080 HTTP/1.1 200 OK connection: keep-alive @@ -44,4 +37,4 @@ content-length: 16 content-type: text/plain Hello, Alladin! -``` +---- diff --git a/examples/rest_basic_auth/src/toppage_handler.erl b/examples/rest_basic_auth/src/toppage_handler.erl index 18a8caee..2e8250f8 100644 --- a/examples/rest_basic_auth/src/toppage_handler.erl +++ b/examples/rest_basic_auth/src/toppage_handler.erl @@ -13,7 +13,7 @@ init(Req, Opts) -> is_authorized(Req, State) -> case cowboy_req:parse_header(<<"authorization">>, Req) of - {<<"basic">>, {User = <<"Alladin">>, <<"open sesame">>}} -> + {basic, User = <<"Alladin">>, <<"open sesame">>} -> {true, Req, User}; _ -> {{false, <<"Basic realm=\"cowboy\"">>}, Req, State} diff --git a/examples/rest_hello_world/README.md b/examples/rest_hello_world/README.asciidoc similarity index 73% rename from examples/rest_hello_world/README.md rename to examples/rest_hello_world/README.asciidoc index c7e124ce..5eb94e8a 100644 --- a/examples/rest_hello_world/README.md +++ b/examples/rest_hello_world/README.asciidoc @@ -1,28 +1,20 @@ -REST hello world example -======================== += REST hello world example To try this example, you need GNU `make` and `git` in your PATH. -To build the example, run the following command: +To build and run the example, use the following command: -``` bash -$ make -``` +[source,bash] +$ make run -To start the release in the foreground: +Then point your browser to http://localhost:8080 -``` bash -$ ./_rel/rest_hello_world_example/bin/rest_hello_world_example console -``` - -Then point your browser at [http://localhost:8080](http://localhost:8080). - -Example output --------------- +== Example output Request HTML: -``` bash +[source,bash] +---- $ curl -i http://localhost:8080 HTTP/1.1 200 OK connection: keep-alive @@ -41,11 +33,12 @@ vary: Accept
REST Hello World as HTML!