<commit_before>-module(iorio_listen_handler).

-export([init/4, stream/3, info/3, terminate/2]).

-ignore_xref([init/4, stream/3, info/3, terminate/2]).

-include_lib("sblob/include/sblob.hrl").
-include("include/iorio.hrl").

-record(state, {channels=[], iorio, token, info, access}).

init(_Transport, Req, [_, {access, Access}|_]=Opts, Active) ->
    Iorio = proplists:get_value(iorio, Opts, iorio),
    {Token, Req1} = cowboy_req:qs_val(<<"jwt">>, Req, nil),
    {Params, Req2} = cowboy_req:qs_vals(Req1),
    RawSubs = proplists:get_all_values(<<"s">>, Params),
    Subs = iorio_parse:subscriptions(RawSubs),
    {ok, Info} = ioriol_access:new_req([]),
    case iorio_session:fill_session_from_token(Access, Info, Token) of
        {ok, Info1} ->
            State = #state{channels=[], iorio=Iorio, access=Access,
                           token=Token, info=Info1},

            State1 = subscribe_all(Subs, State),
            Req3 = if Active == once -> set_json_response(Req2);
                      true -> Req2
                   end,
            {ok, Req3, State1};
        {error, Reason} ->
            lager:warning("shutdown listen ~p", [Reason]),
            {shutdown, Req2, #state{}}
    end.

<commit_msg>compact request on bullet handler<commit_after>-module(iorio_listen_handler).

-export([init/4, stream/3, info/3, terminate/2]).

-ignore_xref([init/4, stream/3, info/3, terminate/2]).

-include_lib("sblob/include/sblob.hrl").
-include("include/iorio.hrl").

-record(state, {channels=[], iorio, token, info, access}).

init(_Transport, Req, [_, {access, Access}|_]=Opts, Active) ->
    Iorio = proplists:get_value(iorio, Opts, iorio),
    {Token, Req1} = cowboy_req:qs_val(<<"jwt">>, Req, nil),
    {Params, Req2} = cowboy_req:qs_vals(Req1),
    Req3 = cowboy_req:compact(Req2),
    RawSubs = proplists:get_all_values(<<"s">>, Params),
    Subs = iorio_parse:subscriptions(RawSubs),
    {ok, Info} = ioriol_access:new_req([]),
    case iorio_session:fill_session_from_token(Access, Info, Token) of
        {ok, Info1} ->
            State = #state{channels=[], iorio=Iorio, access=Access,
                           token=Token, info=Info1},

            State1 = subscribe_all(Subs, State),
            Req3 = if Active == once -> set_json_response(Req3);
                      true -> Req3
                   end,
            {ok, Req3, State1};
        {error, Reason} ->
            lager:warning("shutdown listen ~p", [Reason]),
            {shutdown, Req3, #state{}}
    end.


{'fraction_non_alphanumeric': 0.16699880430450378, 'fraction_numerical': 0.016739736946990835, 'mean_word_length': 2.837920489296636, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 21, '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': '6618708', 'n_tokens_mistral': 907, 'n_tokens_neox': 886, 'n_words': 164}