<commit_before>%% vim: ts=4 sw=4 et
% Simple Bridge Cowboy
% Copyright (c) 2012 <NAME>
% See MIT-LICENSE for licensing information.

-module (cowboy_simple_bridge).
-behaviour (simple_bridge).
-include("simple_bridge.hrl").

%% REQUEST EXPORTS

-export([
        init/1,
        protocol/1,
        request_method/1,
        path/1,
        uri/1,
        peer_ip/1,
        peer_port/1,
        headers/1,
        cookies/1,
        query_params/1,
        post_params/1,
        request_body/1,
        socket/1,
        recv_from_socket/3,
        protocol_version/1
    ]).

%% RESPONSE EXPORTS
-export([
        build_response/2
    ]).

%% HELPER STREAMING EXPORTS
-export([
	 stream_body/1
	]).

new_key() ->
    {cowboy_bridge, erlang:make_ref()}.

get_key(ReqKey) ->
    try
        RequestCache = #request_cache{request = Req} = cowboy_request_server:get(ReqKey),
        {RequestCache, Req}
    catch Class:Reason:Stacktrace  ->
        error_logger:info_msg("~p:~p~n~p", [Class, Reason, Stacktrace])
    end.

put_key(ReqKey, NewRequestCache) ->
    cowboy_request_server:set(ReqKey, NewRequestCache).


init({Req, DocRoot}) ->
    ReqKey = new_key(),
    put_key(ReqKey, #request_cache{body = not_loaded, docroot=DocRoot, request = Req}),
    ReqKey.
<commit_msg>Cowboy 2.x support (API and Maps adaptation)<commit_after>%% vim: ts=4 sw=4 et
% Simple Bridge Cowboy
% Copyright (c) 2012 <NAME>
% See MIT-LICENSE for licensing information.

-module (cowboy_simple_bridge).
-behaviour (simple_bridge).
-include("simple_bridge.hrl").

%% REQUEST EXPORTS

-export([
        init/1,
        protocol/1,
        request_method/1,
        path/1,
        uri/1,
        peer_ip/1,
        peer_port/1,
        headers/1,
        cookies/1,
        query_params/1,
        post_params/1,
        request_body/1,
        socket/1,
        recv_from_socket/3,
        protocol_version/1
    ]).

%% RESPONSE EXPORTS
-export([
        build_response/2
    ]).

%% HELPER STREAMING EXPORTS
-export([
	 stream_body/1
	]).

new_key() ->
    {cowboy_bridge, erlang:make_ref()}.

get_key(ReqKey) ->
    try
        RequestCache = #request_cache{request = Req} = cowboy_request_server:get(ReqKey),
        {RequestCache, Req}
    catch E:T  ->
        error_logger:info_msg("~p:~p~n~p", [E, T, erlang:get_stacktrace()])
    end.

put_key(ReqKey, NewRequestCache) ->
    cowboy_request_server:set(ReqKey, NewRequestCache).


init({Req, DocRoot}) ->
    ReqKey = new_key(),
    put_key(ReqKey, #request_cache{body = not_loaded, docroot=DocRoot, request = Req}),
    ReqKey.

{'fraction_non_alphanumeric': 0.13361901051811453, 'fraction_numerical': 0.018309310479158552, 'mean_word_length': 2.6373937677053823, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2135440', 'n_tokens_mistral': 947, 'n_tokens_neox': 926, 'n_words': 170}