<commit_before>%%%-------------------------------------------------------------------
%% @doc spread cowboy interface. 
%% @end
%%%-------------------------------------------------------------------
-module(spread_cowboy).

-export([
    start/0,
    get_auth/1
]).

%%====================================================================
%% API functions
%%====================================================================

start() ->
    Dispatch = cowboy_router:compile([
        {'_', [
            {"/sse/[...]", spread_cowboy_sse, []},
            {"/ws/[...]", spread_cowboy_ws, []},
            {"/socket.io/[...]", spread_cowboy_socket_io, []},
            {"/jwttoken", spread_jwt_auth, []},
            {"/raw/[...]", spread_cowboy_http, []},
            {"/", cowboy_static, {file, "/var/www/html/index.html"}},
            {"/[...]", cowboy_static, {dir, "/var/www/html"}}
        ]}
    ]),
    cowboy:start_clear(http_listener,
        [{port, 8080}],
        #{
            env => #{dispatch => Dispatch}
            ,request_timeout => 60000
            %,stream_handlers => [cowboy_compress_h, cowboy_stream_h]
        }
    ).

get_auth(Req) ->
    case cowboy_req:header(<<"authorization">>, Req) of
        <<"Bearer ", Authorization/binary>> ->
            spread_jwt_auth:auth(Authorization);
        _ ->
            lager:info("Unsecure connection, should be refusing it"),
            error
    end.<commit_msg>Added ability to pass auth in query string instead of headers<commit_after>%%%-------------------------------------------------------------------
%% @doc spread cowboy interface. 
%% @end
%%%-------------------------------------------------------------------
-module(spread_cowboy).

-export([
    start/0,
    get_auth/1
]).

%%====================================================================
%% API functions
%%====================================================================

start() ->
    Dispatch = cowboy_router:compile([
        {'_', [
            {"/sse/[...]", spread_cowboy_sse, []},
            {"/ws/[...]", spread_cowboy_ws, []},
            {"/socket.io/[...]", spread_cowboy_socket_io, []},
            {"/jwttoken", spread_jwt_auth, []},
            {"/raw/[...]", spread_cowboy_http, []},
            {"/", cowboy_static, {file, "/var/www/html/index.html"}},
            {"/[...]", cowboy_static, {dir, "/var/www/html"}}
        ]}
    ]),
    cowboy:start_clear(http_listener,
        [{port, 8080}],
        #{
            env => #{dispatch => Dispatch}
            ,request_timeout => 60000
            %,stream_handlers => [cowboy_compress_h, cowboy_stream_h]
        }
    ).

get_auth(Req) ->
    case cowboy_req:header(<<"authorization">>, Req) of
        <<"Bearer ", Authorization/binary>> ->
            spread_jwt_auth:auth(Authorization);
        _ ->
            QsVals = cowboy_req:parse_qs(Req),
            case lists:keyfind(<<"authorization">>, 1, QsVals) of
                <<"Bearer ", Authorization/binary>> ->
                    spread_jwt_auth:auth(Authorization);
                _ ->
                    lager:info("Unsecure connection, should be refusing it"),
                    error
            end
    end.
{'fraction_non_alphanumeric': 0.3252184769038702, 'fraction_numerical': 0.00717852684144819, 'mean_word_length': 1.7253401360544218, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '2843902', 'n_tokens_mistral': 924, 'n_tokens_neox': 883, 'n_words': 136}