<commit_before>-module(elli_request).
-include("elli.hrl").

-export([send_chunk/2, chunk_ref/1, path/1, raw_path/1, get_header/2,
         get_arg/2, get_arg/3, headers/1, peer/1, method/1]).

%%
%% Helpers for working with a #req{}
%%

%% @doc: Returns path split into binary parts.
path(#req{path = Path})                     -> Path.
raw_path(#req{raw_path = {abs_path, Path}}) -> Path.
headers(#req{headers = Headers})            -> Headers.
peer(#req{peer = Peer})                     -> Peer.
method(#req{method = Method})               -> Method.

get_header(Key, #req{headers = Headers}) ->
    proplists:get_value(Key, Headers).

get_arg(Key, #req{} = Req) ->
    get_arg(Key, Req, undefined).

get_arg(Key, #req{args = Args}, Default) ->
    proplists:get_value(Key, Args, Default).

%% @doc: Returns a reference that can be used to send chunks to the
%% client. If the protocol does not support it, returns {error,
%% not_supported}.
chunk_ref(#req{version = {1, 1}} = Req) ->
    Req#req.pid;
chunk_ref(_) ->
    {error, not_supported}.


send_chunk(Ref, Data) ->
    Ref ! {chunk, Data, self()},
    receive
        {Ref, ok} ->
            ok;<commit_msg>Return default value when there is no get arguments.<commit_after>-module(elli_request).
-include("elli.hrl").

-export([send_chunk/2, chunk_ref/1, path/1, raw_path/1, get_header/2,
         get_arg/2, get_arg/3, headers/1, peer/1, method/1]).

%%
%% Helpers for working with a #req{}
%%

%% @doc: Returns path split into binary parts.
path(#req{path = Path})                     -> Path.
raw_path(#req{raw_path = {abs_path, Path}}) -> Path.
headers(#req{headers = Headers})            -> Headers.
peer(#req{peer = Peer})                     -> Peer.
method(#req{method = Method})               -> Method.

get_header(Key, #req{headers = Headers}) ->
    proplists:get_value(Key, Headers).

get_arg(Key, #req{} = Req) ->
    get_arg(Key, Req, undefined).

get_arg(_Key, #req{args = []}, Default) ->
    Default;
get_arg(Key, #req{args = Args}, Default) ->
    proplists:get_value(Key, Args, Default).

%% @doc: Returns a reference that can be used to send chunks to the
%% client. If the protocol does not support it, returns {error,
%% not_supported}.
chunk_ref(#req{version = {1, 1}} = Req) ->
    Req#req.pid;
chunk_ref(_) ->
    {error, not_supported}.


send_chunk(Ref, Data) ->
    Ref ! {chunk, Data, self()},
    receive
        {Ref, ok} ->
            ok;
{'fraction_non_alphanumeric': 0.17084188911704312, 'fraction_numerical': 0.009856262833675565, 'mean_word_length': 2.878980891719745, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 28, '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': '5963067', 'n_tokens_mistral': 862, 'n_tokens_neox': 836, 'n_words': 213}