<commit_before>-module(qri_emitter).

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


init(Req, Opts) ->
    PID = self(),
    qri_peer:register(qri_peer:parse_qs(Req), PID),

    Headers = [
        {<<"content-type">>, <<"text/event-stream">>},
        {<<"Cache-Control">>, <<"no-cache">>}
    ],
    Req2 = cowboy_req:chunked_reply(200, Headers, Req),

    PID ! {message, "Tick"},

    {cowboy_loop, Req2, Opts}.

info({message, Msg}, Req, State) ->
    Chunk = [
        "id: ", qri_peer:generate_tick_id(),
        "\ndata: ", Msg,
        "\n\n"
    ],

    cowboy_req:chunk(Chunk, Req),

    {ok, Req, State}.

terminate(_Reason, Req, _State) ->
    qri_peer:remove(qri_peer:parse_qs(Req)),<commit_msg>Implement: cross origin headers.<commit_after>-module(qri_emitter).

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


init(Req, Opts) ->
    PID = self(),
    qri_peer:register(qri_peer:parse_qs(Req), PID),

    Headers = [
        {<<"content-type">>, <<"text/event-stream">>},
        {<<"Cache-Control">>, <<"no-cache">>},
        {<<"access-control-allow-origin">>, <<"*">>},
        {<<"access-control-allow-methods">>, <<"*">>}
    ],
    Req2 = cowboy_req:chunked_reply(200, Headers, Req),

    PID ! {message, "Tick"},

    {cowboy_loop, Req2, Opts}.

info({message, Msg}, Req, State) ->
    Chunk = [
        "id: ", qri_peer:generate_tick_id(),
        "\ndata: ", Msg,
        "\n\n"
    ],

    cowboy_req:chunk(Chunk, Req),

    {ok, Req, State}.

terminate(_Reason, Req, _State) ->
    qri_peer:remove(qri_peer:parse_qs(Req)),
{'fraction_non_alphanumeric': 0.21976592977893367, 'fraction_numerical': 0.010403120936280884, 'mean_word_length': 3.0393700787401574, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 33, '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': '7206727', 'n_tokens_mistral': 637, 'n_tokens_neox': 609, 'n_words': 92}