aboutsummaryrefslogtreecommitdiffstats
path: root/lib/dialyzer/test/opaque_SUITE_data/src/ewgi/ewgi_api.erl
blob: 60da757d3b6d631a812b3a59cd0b209cf9cd399a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
%%%-------------------------------------------------------------------
%%% File    : ewgi_api.erl
%%% Authors : Filippo Pacini <[email protected]>
%%%           Hunter Morris <[email protected]>
%%% License :
%%% The contents of this file are subject to the Mozilla Public
%%% License Version 1.1 (the "License"); you may not use this file
%%% except in compliance with the License. You may obtain a copy of
%%% the License at http://www.mozilla.org/MPL/
%%%
%%% Software distributed under the License is distributed on an "AS IS"
%%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
%%% the License for the specific language governing rights and
%%% limitations under the License.
%%% The Initial Developer of the Original Code is S.G. Consulting
%%% srl. Portions created by S.G. Consulting s.r.l. are Copyright (C)
%%% 2007 S.G. Consulting srl. All Rights Reserved.
%%%
%%% @doc
%%% <p>ewgi API. Defines a low level CGI like API.</p>
%%%
%%% @end
%%%
%%% Created : 10 Oct 2007 by Filippo Pacini <[email protected]>
%%%-------------------------------------------------------------------
-module(ewgi_api).

-include_lib("ewgi.hrl").

-export([get_all_headers/1, get_all_data/1]).

-spec request(ewgi_context()) -> ewgi_request().
request(Ctx) when ?IS_EWGI_CONTEXT(Ctx) ->
    ?GET_EWGI_REQUEST(Ctx).

-spec headers(ewgi_context()) -> ewgi_http_headers().
headers(Ctx) when ?IS_EWGI_CONTEXT(Ctx) ->
    ?GET_HTTP_HEADERS(request(Ctx)).

get_header_value(Hdr0, Ctx) when is_list(Hdr0), ?IS_EWGI_CONTEXT(Ctx) ->
    Hdr = string:to_lower(Hdr0),
    get_header1(Hdr, Ctx).

get_header1("accept", Ctx) when ?IS_EWGI_CONTEXT(Ctx) ->
    ?GET_HTTP_ACCEPT(headers(Ctx)).

unzip_header_value([{_,_}|_]=V) ->
	{_, V1} = lists:unzip(V),
	string:join(V1, ", ");
unzip_header_value(V) ->
	V.

get_all_headers(Ctx) when ?IS_EWGI_CONTEXT(Ctx) ->
    H = headers(Ctx),
    Other = gb_trees:to_list(?GET_HTTP_OTHER(H)),
    Acc = [{K, unzip_header_value(V)} || {K, V} <- Other],
    L = [{"accept", get_header_value("accept", Ctx)}|Acc],
    lists:filter(fun({_, undefined}) -> false; (_) -> true end, L).

-spec ewgi_spec(ewgi_context()) -> ewgi_spec().
ewgi_spec(Ctx) when ?IS_EWGI_CONTEXT(Ctx) ->
    ?GET_EWGI(request(Ctx)).

get_all_data(Ctx) when ?IS_EWGI_CONTEXT(Ctx) ->
    ?GET_EWGI_DATA(ewgi_spec(Ctx)).