<commit_before>-module(boss_mochicow_handler).
-export([init/3, loop/1]).

init({ssl, http}, _Req, _Opts) ->
	{upgrade, protocol, mochicow_upgrade};

init({tcp, http}, _Req, _Opts) ->
	{upgrade, protocol, mochicow_upgrade}.

loop(Req) ->
	boss_web_controller:handle_request(Req, mochiweb_request_bridge, mochiweb_response_bridge).
<commit_msg>add cowboy websocket support<commit_after>-module(boss_mochicow_handler).
-behaviour(cowboy_http_websocket_handler).

-export([init/3, loop/1, terminate/2]).
-export([websocket_init/3, websocket_handle/3,
	websocket_info/3, websocket_terminate/3]).

init({_Any, http}, Req, _Opts) ->
    case cowboy_http_req:header('Upgrade', Req) of
	{undefined, _Req2} -> {upgrade, protocol, mochicow_upgrade};
	{<<"websocket">>, _Req2} -> {upgrade, protocol, cowboy_http_websocket};
	{<<"WebSocket">>, _Req2} -> {upgrade, protocol, cowboy_http_websocket}
    end.

loop(Req) ->
    boss_web_controller:handle_request(Req, mochiweb_request_bridge, mochiweb_response_bridge).

terminate(_Req, _State) ->
    ok.

websocket_init(_Any, Req, _Opts) ->
    {ok, Req, State, hibernate}.

websocket_handle({text, Msg}, Req, State) ->
    error_logger:info_msg("websocket: message:~p Pid ~p~nState=~p~n", 
			  [Msg, erlang:pid_to_list(self()), State]),    
    {reply, {text, "copy" }, Req, State, hibernate};

websocket_handle(_Any, Req, State) ->
    {ok, Req, State}.

websocket_info({text, Msg}, Req, State) ->
    {reply, {text, Msg}, Req, State};

websocket_info(_Info, Req, State) ->
    {ok, Req, State, hibernate}.

websocket_terminate(_Reason, _Req, _State) ->
    %% boss:mq ??
    ok.

{'fraction_non_alphanumeric': 0.16800494132180357, 'fraction_numerical': 0.0074119827053736875, 'mean_word_length': 5.303501945525292, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 22, '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': '7569873', 'n_tokens_mistral': 654, 'n_tokens_neox': 631, 'n_words': 115}