Created
December 19, 2008 12:55
-
-
Save nicolasff/38000 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(server). | |
-export([start/0]). | |
% 1 - Download and install Mochiweb, make sure it is in the ebin path (-pa). | |
% 2 - Run with server:start() | |
% 3 - Point you browser to http://127.0.0.1:12345/something | |
% 4 - A primitive benchmark: "ab -c 1000 -n 10000 http://127.0.0.1:12345/test" | |
start() -> | |
Options = [ | |
{max, 1000000}, | |
{name, ?MODULE}, | |
{port, 12345}, | |
{loop, fun handle_query/1}], | |
mochiweb_http:start(Options). | |
handle_query(Req) -> | |
"/" ++ Path = Req:get(path), | |
Req:respond({200, | |
[{"Content-Type", "text-plain"}], | |
"Hello, you requested [" ++ Path ++ "]\r\n"}), | |
% Or chunked, for Comet streaming: | |
% | |
% Response = Req:ok({"text/plain; charset=utf-8", [], chunked}), | |
% Response:write_chunk("Hello, you requested [" ++ Path ++ "]\r\n"), | |
% Response:write_chunk([]), | |
ok. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment