Browse Source

Merge pull request #1871 from blee-techempower/update-erlang-cowboy

Update Erlang/cowboy: add plain text route
Mike Smith 9 years ago
parent
commit
8366f62d60

+ 1 - 0
frameworks/Erlang/cowboy/benchmark_config.json

@@ -3,6 +3,7 @@
   "tests": [{
   "tests": [{
     "default": {
     "default": {
       "setup_file": "setup",
       "setup_file": "setup",
+      "plaintext_url": "/plaintext",
       "json_url": "/json",
       "json_url": "/json",
       "db_url": "/db",
       "db_url": "/db",
       "query_url": "/query?queries=",
       "query_url": "/query?queries=",

+ 1 - 0
frameworks/Erlang/cowboy/src/hello_world_app.erl

@@ -25,6 +25,7 @@ start(_Type, _Args) ->
 	emysql:prepare(db_stmt, <<"SELECT * FROM World where id = ?">>),
 	emysql:prepare(db_stmt, <<"SELECT * FROM World where id = ?">>),
 	Dispatch = cowboy_router:compile([
 	Dispatch = cowboy_router:compile([
 		{'_', [
 		{'_', [
+      {"/plaintext", plaintext_handler, []},
 			{"/json", json_handler, []},
 			{"/json", json_handler, []},
 			{"/db", db_handler, []},
 			{"/db", db_handler, []},
       {"/query", query_handler, []}
       {"/query", query_handler, []}

+ 18 - 0
frameworks/Erlang/cowboy/src/plaintext_handler.erl

@@ -0,0 +1,18 @@
+%% Feel free to use, reuse and abuse the code in this file.
+
+%% @doc Hello world handler.
+-module(plaintext_handler).
+
+-export([init/3]).
+-export([handle/2]).
+-export([terminate/3]).
+
+init(_Transport, Req, []) ->
+  {ok, Req, undefined}.
+
+handle(Req, State) ->
+  {ok, Req2} = cowboy_req:reply(200, [{<<"Content-Type">>, <<"text/plain">>}], <<"Hello, World!">>, Req),
+  {ok, Req2, State}.
+
+terminate(_Reason, _Req, _State) ->
+  ok.