mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-15 20:50:24 +00:00

Simplify the interface for most cowboy_req functions. They all return a single value except the four body reading functions. The reply functions now only return a Req value. Access functions do not return a Req anymore. Functions that used to cache results do not have a cache anymore. The interface for accessing query string and cookies has therefore been changed. There are now three query string functions: qs/1 provides access to the raw query string value; parse_qs/1 returns the query string as a list of key/values; match_qs/2 returns a map containing the values requested in the second argument, after applying constraints and default value. Similarly, there are two cookie functions: parse_cookies/1 and match_cookies/2. More match functions will be added in future commits. None of the functions return an error tuple anymore. It either works or crashes. Cowboy will attempt to provide an appropriate status code in the response of crashed handlers. As a result, the content decode function has its return value changed to a simple binary, and the body reading functions only return on success.
31 lines
1.3 KiB
Erlang
31 lines
1.3 KiB
Erlang
%% Feel free to use, reuse and abuse the code in this file.
|
|
|
|
%% @doc Compress response handler.
|
|
-module(toppage_handler).
|
|
|
|
-export([init/3]).
|
|
-export([handle/2]).
|
|
-export([terminate/3]).
|
|
|
|
init(_Transport, Req, []) ->
|
|
{ok, Req, undefined}.
|
|
|
|
handle(Req, State) ->
|
|
BigBody =
|
|
<<"A cowboy is an animal herder who tends cattle on ranches in North America,
|
|
traditionally on horseback, and often performs a multitude of other ranch-
|
|
related tasks. The historic American cowboy of the late 19th century arose
|
|
from the vaquero traditions of northern Mexico and became a figure of special
|
|
significance and legend. A subtype, called a wrangler, specifically tends the
|
|
horses used to work cattle. In addition to ranch work, some cowboys work for
|
|
or participate in rodeos. Cowgirls, first defined as such in the late 19th
|
|
century, had a less-well documented historical role, but in the modern world
|
|
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.\n">>,
|
|
Req2 = cowboy_req:reply(200, [], BigBody, Req),
|
|
{ok, Req2, State}.
|
|
|
|
terminate(_Reason, _Req, _State) ->
|
|
ok.
|