aboutsummaryrefslogblamecommitdiffstats
path: root/test/http_SUITE_data/rest_resource_etags.erl
blob: fb266d10ea2ae12f27f840802811ca33b974d3eb (plain) (tree)
1
2
3
4
5
6
7
8
9



                                                                               
                                         

                            

                                                           
                                                              



                                                                        
                                                                           



                                                                    
                                                              
                                               
                                                                             

                                                              
                                                                             
                                                               






                                                                        
-module(rest_resource_etags).
-export([init/3, generate_etag/2, content_types_provided/2, get_text_plain/2]).

init(_Transport, _Req, _Opts) ->
	{upgrade, protocol, cowboy_rest}.

generate_etag(Req, State) ->
	#{type := Type} = cowboy_req:match_qs(Req, [type]),
	case Type of
		%% Correct return values from generate_etag/2.
		<<"tuple-weak">> ->
			{{weak, <<"etag-header-value">>}, Req, State};
		<<"tuple-strong">> ->
			{{strong, <<"etag-header-value">>}, Req, State};
		%% Backwards compatible return values from generate_etag/2.
		<<"binary-weak-quoted">> ->
			{<<"W/\"etag-header-value\"">>, Req, State};
		<<"binary-strong-quoted">> ->
			{<<"\"etag-header-value\"">>, Req, State};
		%% Invalid return values from generate_etag/2.
		<<"binary-strong-unquoted">> ->
			cowboy_error_h:ignore(cowboy_http, quoted_string, 2),
			{<<"etag-header-value">>, Req, State};
		<<"binary-weak-unquoted">> ->
			cowboy_error_h:ignore(cowboy_http, quoted_string, 2),
			{<<"W/etag-header-value">>, Req, State}
	end.

content_types_provided(Req, State) ->
	{[{{<<"text">>, <<"plain">>, []}, get_text_plain}], Req, State}.

get_text_plain(Req, State) ->
	{<<"This is REST!">>, Req, State}.