tests: serve simple and complex binary
authorJean Privat <jean@pryen.org>
Thu, 31 May 2018 18:21:10 +0000 (14:21 -0400)
committerJean Privat <jean@pryen.org>
Thu, 31 May 2018 19:52:25 +0000 (15:52 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

tests/sav/test_nitcorn.res
tests/test_nitcorn.nit

index 9ee42f3..6a13937 100644 (file)
@@ -128,3 +128,10 @@ Content-Length: 0
 Server: nitcorn\r
 Set-Cookie: nitcorn_session=; HttpOnly; expires=Thu, 01 Jan 1970 00:00:00 GMT\r
 \r
+
+[Client] curl -s localhost:*****/simple_binary/
+ñòó
+
+[Client] curl -s localhost:*****/simple_template/
+Hello
+ñòó
index b7fcd90..7f9c9d6 100644 (file)
@@ -30,23 +30,49 @@ class MyAction
        redef fun answer(request, turi)
        do
                var rep = new HttpResponse(200)
-               rep.body = """
+               var body = """
 [Response] Simple answer
 Method: {{{request.method}}}, URI: {{{request.uri}}}, trailing: {{{turi}}}"""
 
                if request.get_args.not_empty
-               then rep.body += "\nGET args: {request.get_args.join(", ", ":")}"
+               then body += "\nGET args: {request.get_args.join(", ", ":")}"
 
                if request.post_args.not_empty
-               then rep.body += "\nPOST args: {request.post_args.join(", ", ":")}"
+               then body += "\nPOST args: {request.post_args.join(", ", ":")}"
 
                if request.uri_params.not_empty
-               then rep.body += "\nParams args: {request.uri_params.join(", ", ":")}"
+               then body += "\nParams args: {request.uri_params.join(", ", ":")}"
 
                if request.cookie.not_empty
-               then rep.body += "\nCookie: {request.cookie.join(", ", ":")}"
+               then body += "\nCookie: {request.cookie.join(", ", ":")}"
 
-               rep.body += "\n"
+               body += "\n"
+               rep.body = body
+               return rep
+       end
+end
+
+class MyBinAction
+       super Action
+
+       redef fun answer(request, turi)
+       do
+               var rep = new HttpResponse(200)
+               rep.body = b"\xF1\xF2\xF3\n"
+               return rep
+       end
+end
+
+class MyTmplAction
+       super Action
+
+       redef fun answer(request, turi)
+       do
+               var rep = new HttpResponse(200)
+               var body = new Template
+               body.add "Hello\n"
+               body.add b"\xF1\xF2\xF3\n"
+               rep.body = body
                return rep
        end
 end
@@ -64,6 +90,8 @@ class ServerThread
                vh.routes.add new Route("file_server", new FileServer(fs_path.simplify_path))
                vh.routes.add new Route("simple_answer", new MyAction)
                vh.routes.add new Route("params_answer/:i/:s", new MyAction)
+               vh.routes.add new Route("simple_binary", new MyBinAction)
+               vh.routes.add new Route("simple_template", new MyTmplAction)
 
                # Launch
                var factory = new HttpFactory.and_libevent
@@ -104,6 +132,9 @@ class ClientThread
                system "curl -s {iface}/file_server/unknown_file.txt --head"
 
                system "curl -s {iface}/invalid_route --head"
+
+               system "curl -s {iface}/simple_binary/"
+               system "curl -s {iface}/simple_template/"
                return null
        end