Commits

Justin Sheehy committed ba756c7

Automated commit message

Comments (0)

Files changed (1)

ExampleResources.wiki

 {{{
 #!erlang
 is_authorized(ReqData, Context) ->
-    case webmachine_reqdata:disp_path(ReqData) of
+    case wrq:disp_path(ReqData) of
         "authdemo" -> 
-            case webmachine_reqdata:get_req_header("authorization", ReqData) of
+            case wrq:get_req_header("authorization", ReqData) of
                 "Basic "++Base64 ->
                     Str = base64:mime_decode_to_string(Base64),
                     case string:tokens(Str, ":") of
 
 With that function in the resource, all paths except {{{ /authdemo }}} from this resource's root are authorized. For that one path, the UA will be asked to do basic authorization with the user/pass of authdemo/demo1. It should go without saying that this isn't quite the same function that we use in our real apps, but it is nice and simple.
 
+To see that it works, you can point your browser at {{{ http://localhost:8000/demo/authdemo }}} with the demo app running:
+
+{{{
+$ curl -v http://localhost:8000/demo/authdemo
+> GET /demo/authdemo HTTP/1.1
+> Host: localhost:8000
+> Accept: */*
+> 
+< HTTP/1.1 401 Unauthorized
+< WWW-Authenticate: Basic realm=webmachine
+< Server: MochiWeb/1.1 WebMachine/0.97
+< Date: Sun, 15 Mar 2009 02:57:43 GMT
+< Content-Length: 0
+< 
+}}}
+{{{
+$ curl -v -u authdemo:demo1 http://localhost:8000/demo/authdemo 
+* Server auth using Basic with user 'authdemo'
+> GET /demo/authdemo HTTP/1.1
+> Authorization: Basic YXV0aGRlbW86ZGVtbzE=
+> Host: localhost:8000
+> Accept: */*
+> 
+< HTTP/1.1 200 OK
+< Vary: Accept
+< Server: MochiWeb/1.1 WebMachine/0.97
+< Date: Sun, 15 Mar 2009 02:59:02 GMT
+< Content-Type: text/html
+< Content-Length: 59
+< 
+<html><body>Hello authdemo from webmachine.
+</body></html>
+}}}
+
 HTTP caching support is also quite easy, with functions allowing resources to define {{{ last_modified }}} , {{{ expires }}}, and {{{ generate_etag }}}. For instance, since representations of this resource vary only by URI Path, I could use an extremely simple entity tag unfit for most real applications but sufficient for this example:
 
 {{{