<commit_before>%%----------------------------------------------------------------------
%%% File    : yaws_api.erl
%%% Author  : <NAME> <<EMAIL>>
%%% Purpose :
%%% Created : 24 Jan 2002 by <NAME> <<EMAIL>>
%%%----------------------------------------------------------------------

-module(yaws_api).
-author('<EMAIL>').

-include("../include/yaws.hrl").
-include("../include/yaws_api.hrl").
-include("yaws_debug.hrl").



-export([parse_query/1, parse_post/1,
         parse_multipart_post/1, parse_multipart_post/2,
         parse_multipart/2, parse_multipart/3]).
-export([code_to_phrase/1, ssi/2, redirect/1]).
-export([setcookie/2, setcookie/3, setcookie/4, setcookie/5, setcookie/6]).
-deprecated([{setcookie, 2, eventually},
             {setcookie, 3, eventually},
             {setcookie, 4, eventually},
             {setcookie, 5, eventually},
             {setcookie, 6, eventually}]).
-export([set_cookie/3]).
-export([pre_ssi_files/2,  pre_ssi_string/1, pre_ssi_string/2,
         set_content_type/1,
         htmlize/1, htmlize_char/1, f/2, fl/1]).
-export([find_cookie_val/2, secs/0,
         url_decode/1, url_decode_q_split/1,
         url_encode/1, parse_url/1, parse_url/2, format_url/1,
         format_partial_url/2]).
-export([is_absolute_URI/1]).
-export([path_norm/1, path_norm_reverse/1,
         sanitize_file_name/1]).
-export([get_line/1, mime_type/1, mime_type/2]).
-export([stream_chunk_deliver/2, stream_chunk_deliver_blocking/2,
         stream_chunk_end/1]).
-export([stream_process_deliver/2, stream_process_deliver_chunk/2,
         stream_process_deliver_final_chunk/2, stream_process_end/2]).
-export([websocket_send/2]).
-export([get_sslsocket/1]).
-export([new_cookie_session/1, new_cookie_session/2, new_cookie_session/3,
         cookieval_to_opaque/1, request_url/1,
         print_cookie_sessions/0,
         replace_cookie_session/2, replace_cookie_session/3,
         delete_cookie_session/1]).

-export([getconf/0,
         setconf/2,
         get_listen_port/1,
         embedded_start_conf/1, embedded_start_conf/2,
         embedded_start_conf/3, embedded_start_conf/4]).

-export([set_status_code/1, reformat_header/1, reformat_header/2,
         reformat_request/1, reformat_response/1, reformat_url/1]).

-export([set_trace/1,
         set_tty_trace/1,
         set_access_log/1]).

-export([call_cgi/2, call_cgi/3]).

-export([call_fcgi_responder/1, call_fcgi_responder/2,
         call_fcgi_authorizer/1, call_fcgi_authorizer/2]).

-export([ehtml_expand/1, ehtml_expander/1, ehtml_apply/2,
         ehtml_expander_test/0]).

-export([parse_set_cookie/1, parse_cookie/1, format_set_cookie/1,
         format_cookie/1, postvar/2, queryvar/2, getvar/2]).

-export([binding/1,binding_exists/1,
         dir_listing/1, dir_listing/2, redirect_self/1]).

-export([arg_clisock/1, arg_client_ip_port/1, arg_headers/1, arg_req/1,
         arg_orig_req/1, arg_clidata/1, arg_server_path/1, arg_querydata/1,
         arg_appmoddata/1, arg_docroot/1, arg_docroot_mount/1, arg_fullpath/1,
         arg_cont/1, arg_state/1, arg_pid/1, arg_opaque/1, arg_appmod_prepath/1,
         arg_prepath/1,
         arg_pathinfo/1]).
-export([http_request_method/1, http_request_path/1, http_request_version/1,
         http_response_version/1, http_response_status/1,
         http_response_phrase/1,
         headers_connection/1, headers_accept/1, headers_host/1,
         headers_if_modified_since/1, headers_if_match/1,
         headers_if_none_match/1,
         headers_if_range/1, headers_if_unmodified_since/1, headers_range/1,
         headers_referer/1, headers_user_agent/1, headers_accept_ranges/1,
         headers_cookie/1, headers_keep_alive/1, headers_location/1,
         headers_content_length/1, headers_content_type/1,
         headers_content_encoding/1, headers_authorization/1,
         headers_transfer_encoding/1, headers_x_forwarded_for/1,
         headers_other/1]).

-export([set_header/2, set_header/3, merge_header/2, merge_header/3,
         get_header/2, get_header/3, delete_header/2]).

-import(lists, [flatten/1, reverse/1]).

%% These are a bunch of accessor functions that are useful inside
%% yaws scripts.

arg_clisock(#arg{clisock = X}) -> X.
arg_client_ip_port(#arg{client_ip_port = X}) -> X.
arg_headers(#arg{headers = X}) -> X.
arg_req(#arg{req = X}) -> X.
arg_orig_req(#arg{orig_req = X}) -> X.
arg_clidata(#arg{clidata = X}) -> X.
arg_server_path(#arg{server_path = X}) -> X.
arg_querydata(#arg{querydata = X}) -> X.
arg_appmoddata(#arg{appmoddata = X}) -> X.
arg_docroot(#arg{docroot = X}) -> X.
arg_docroot_mount(#arg{docroot_mount = X}) -> X.
arg_fullpath(#arg{fullpath = X}) -> X.
arg_cont(#arg{cont = X}) -> X.
arg_state(#arg{state = X}) -> X.
arg_pid(#arg{pid = X}) -> X.
arg_opaque(#arg{opaque = X}) -> X.
arg_appmod_prepath(#arg{appmod_prepath = X}) -> X.
arg_prepath(#arg{prepath = X}) -> X.
arg_pathinfo(#arg{pathinfo = X}) ->  X.

http_request_method(#http_request{method = X}) -> X.
http_request_path(#http_request{path = X}) -> X.
http_request_version(#http_request{version = X}) -> X.

http_response_version(#http_response{version = X}) -> X.
http_response_status(#http_response{status = X}) -> X.
http_response_phrase(#http_response{phrase = X}) -> X.

headers_connection(#headers{connection = X}) -> X.
headers_accept(#headers{accept = X}) -> X.
headers_host(#headers{host = X}) -> X.
headers_if_modified_since(#headers{if_modified_since = X}) -> X.
headers_if_match(#headers{if_match = X}) -> X.
headers_if_none_match(#headers{if_none_match = X}) -> X.
headers_if_range(#headers{if_range = X}) -> X.
headers_if_unmodified_since(#headers{if_unmodified_since = X}) -> X.
headers_range(#headers{range = X}) -> X.
headers_referer(#headers{referer = X}) -> X.
headers_user_agent(#headers{user_agent = X}) -> X.
headers_accept_ranges(#headers{accept_ranges = X}) -> X.
headers_cookie(#headers{cookie = X}) -> X.
headers_keep_alive(#headers{keep_alive = X}) -> X.
headers_location(#headers{location = X}) -> X.
headers_content_length(#headers{content_length = X}) -> X.
headers_content_type(#headers{content_type = X}) -> X.
headers_content_encoding(#headers{content_encoding = X}) -> X.
headers_authorization(#headers{authorization = X}) -> X.
headers_transfer_encoding(#headers{transfer_encoding = X}) -> X.
headers_x_forwarded_for(#headers{x_forwarded_for = X}) -> X.
headers_other(#headers{other = X}) -> X.


%% parse the command line query data
parse_query(Arg) ->
    case get(query_parse) of
        undefined ->
            Res = case Arg#arg.querydata of
                      [] -> [];
                      D  -> parse_post_data_urlencoded(D)
                  end,
            put(query_parse, Res),
            Res;
        Res ->
            Res
    end.

%% parse url encoded POST data
parse_post(Arg) ->
    case get(post_parse) of
        undefined ->
            H = Arg#arg.headers,
            Res = case H#headers.content_type of
                      "application/x-www-form-urlencoded" ->
                          case Arg#arg.clidata of
                              [] -> [];
                              D  -> parse_post_data_urlencoded(D)
                          end;
                      _ ->
                          []
                  end,
            put(post_parse, Res),
            Res;<commit_msg>yaws_api: Fix matching of Content-Type in parse_post/1<commit_after>%%----------------------------------------------------------------------
%%% File    : yaws_api.erl
%%% Author  : <NAME> <<EMAIL>>
%%% Purpose :
%%% Created : 24 Jan 2002 by <NAME> <<EMAIL>>
%%%----------------------------------------------------------------------

-module(yaws_api).
-author('<EMAIL>').

-include("../include/yaws.hrl").
-include("../include/yaws_api.hrl").
-include("yaws_debug.hrl").



-export([parse_query/1, parse_post/1,
         parse_multipart_post/1, parse_multipart_post/2,
         parse_multipart/2, parse_multipart/3]).
-export([code_to_phrase/1, ssi/2, redirect/1]).
-export([setcookie/2, setcookie/3, setcookie/4, setcookie/5, setcookie/6]).
-deprecated([{setcookie, 2, eventually},
             {setcookie, 3, eventually},
             {setcookie, 4, eventually},
             {setcookie, 5, eventually},
             {setcookie, 6, eventually}]).
-export([set_cookie/3]).
-export([pre_ssi_files/2,  pre_ssi_string/1, pre_ssi_string/2,
         set_content_type/1,
         htmlize/1, htmlize_char/1, f/2, fl/1]).
-export([find_cookie_val/2, secs/0,
         url_decode/1, url_decode_q_split/1,
         url_encode/1, parse_url/1, parse_url/2, format_url/1,
         format_partial_url/2]).
-export([is_absolute_URI/1]).
-export([path_norm/1, path_norm_reverse/1,
         sanitize_file_name/1]).
-export([get_line/1, mime_type/1, mime_type/2]).
-export([stream_chunk_deliver/2, stream_chunk_deliver_blocking/2,
         stream_chunk_end/1]).
-export([stream_process_deliver/2, stream_process_deliver_chunk/2,
         stream_process_deliver_final_chunk/2, stream_process_end/2]).
-export([websocket_send/2]).
-export([get_sslsocket/1]).
-export([new_cookie_session/1, new_cookie_session/2, new_cookie_session/3,
         cookieval_to_opaque/1, request_url/1,
         print_cookie_sessions/0,
         replace_cookie_session/2, replace_cookie_session/3,
         delete_cookie_session/1]).

-export([getconf/0,
         setconf/2,
         get_listen_port/1,
         embedded_start_conf/1, embedded_start_conf/2,
         embedded_start_conf/3, embedded_start_conf/4]).

-export([set_status_code/1, reformat_header/1, reformat_header/2,
         reformat_request/1, reformat_response/1, reformat_url/1]).

-export([set_trace/1,
         set_tty_trace/1,
         set_access_log/1]).

-export([call_cgi/2, call_cgi/3]).

-export([call_fcgi_responder/1, call_fcgi_responder/2,
         call_fcgi_authorizer/1, call_fcgi_authorizer/2]).

-export([ehtml_expand/1, ehtml_expander/1, ehtml_apply/2,
         ehtml_expander_test/0]).

-export([parse_set_cookie/1, parse_cookie/1, format_set_cookie/1,
         format_cookie/1, postvar/2, queryvar/2, getvar/2]).

-export([binding/1,binding_exists/1,
         dir_listing/1, dir_listing/2, redirect_self/1]).

-export([arg_clisock/1, arg_client_ip_port/1, arg_headers/1, arg_req/1,
         arg_orig_req/1, arg_clidata/1, arg_server_path/1, arg_querydata/1,
         arg_appmoddata/1, arg_docroot/1, arg_docroot_mount/1, arg_fullpath/1,
         arg_cont/1, arg_state/1, arg_pid/1, arg_opaque/1, arg_appmod_prepath/1,
         arg_prepath/1,
         arg_pathinfo/1]).
-export([http_request_method/1, http_request_path/1, http_request_version/1,
         http_response_version/1, http_response_status/1,
         http_response_phrase/1,
         headers_connection/1, headers_accept/1, headers_host/1,
         headers_if_modified_since/1, headers_if_match/1,
         headers_if_none_match/1,
         headers_if_range/1, headers_if_unmodified_since/1, headers_range/1,
         headers_referer/1, headers_user_agent/1, headers_accept_ranges/1,
         headers_cookie/1, headers_keep_alive/1, headers_location/1,
         headers_content_length/1, headers_content_type/1,
         headers_content_encoding/1, headers_authorization/1,
         headers_transfer_encoding/1, headers_x_forwarded_for/1,
         headers_other/1]).

-export([set_header/2, set_header/3, merge_header/2, merge_header/3,
         get_header/2, get_header/3, delete_header/2]).

-import(lists, [flatten/1, reverse/1]).

%% These are a bunch of accessor functions that are useful inside
%% yaws scripts.

arg_clisock(#arg{clisock = X}) -> X.
arg_client_ip_port(#arg{client_ip_port = X}) -> X.
arg_headers(#arg{headers = X}) -> X.
arg_req(#arg{req = X}) -> X.
arg_orig_req(#arg{orig_req = X}) -> X.
arg_clidata(#arg{clidata = X}) -> X.
arg_server_path(#arg{server_path = X}) -> X.
arg_querydata(#arg{querydata = X}) -> X.
arg_appmoddata(#arg{appmoddata = X}) -> X.
arg_docroot(#arg{docroot = X}) -> X.
arg_docroot_mount(#arg{docroot_mount = X}) -> X.
arg_fullpath(#arg{fullpath = X}) -> X.
arg_cont(#arg{cont = X}) -> X.
arg_state(#arg{state = X}) -> X.
arg_pid(#arg{pid = X}) -> X.
arg_opaque(#arg{opaque = X}) -> X.
arg_appmod_prepath(#arg{appmod_prepath = X}) -> X.
arg_prepath(#arg{prepath = X}) -> X.
arg_pathinfo(#arg{pathinfo = X}) ->  X.

http_request_method(#http_request{method = X}) -> X.
http_request_path(#http_request{path = X}) -> X.
http_request_version(#http_request{version = X}) -> X.

http_response_version(#http_response{version = X}) -> X.
http_response_status(#http_response{status = X}) -> X.
http_response_phrase(#http_response{phrase = X}) -> X.

headers_connection(#headers{connection = X}) -> X.
headers_accept(#headers{accept = X}) -> X.
headers_host(#headers{host = X}) -> X.
headers_if_modified_since(#headers{if_modified_since = X}) -> X.
headers_if_match(#headers{if_match = X}) -> X.
headers_if_none_match(#headers{if_none_match = X}) -> X.
headers_if_range(#headers{if_range = X}) -> X.
headers_if_unmodified_since(#headers{if_unmodified_since = X}) -> X.
headers_range(#headers{range = X}) -> X.
headers_referer(#headers{referer = X}) -> X.
headers_user_agent(#headers{user_agent = X}) -> X.
headers_accept_ranges(#headers{accept_ranges = X}) -> X.
headers_cookie(#headers{cookie = X}) -> X.
headers_keep_alive(#headers{keep_alive = X}) -> X.
headers_location(#headers{location = X}) -> X.
headers_content_length(#headers{content_length = X}) -> X.
headers_content_type(#headers{content_type = X}) -> X.
headers_content_encoding(#headers{content_encoding = X}) -> X.
headers_authorization(#headers{authorization = X}) -> X.
headers_transfer_encoding(#headers{transfer_encoding = X}) -> X.
headers_x_forwarded_for(#headers{x_forwarded_for = X}) -> X.
headers_other(#headers{other = X}) -> X.


%% parse the command line query data
parse_query(Arg) ->
    case get(query_parse) of
        undefined ->
            Res = case Arg#arg.querydata of
                      [] -> [];
                      D  -> parse_post_data_urlencoded(D)
                  end,
            put(query_parse, Res),
            Res;
        Res ->
            Res
    end.

%% parse url encoded POST data
parse_post(Arg) ->
    case get(post_parse) of
        undefined ->
            H = Arg#arg.headers,
            Res = case H#headers.content_type of
                      "application/x-www-form-urlencoded"++_ ->
                          case Arg#arg.clidata of
                              [] -> [];
                              D  -> parse_post_data_urlencoded(D)
                          end;
                      _ ->
                          []
                  end,
            put(post_parse, Res),
            Res;
{'fraction_non_alphanumeric': 0.16246937108630546, 'fraction_numerical': 0.022120882112714402, 'mean_word_length': 2.933868808567604, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 133, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3989236', 'n_tokens_mistral': 5261, 'n_tokens_neox': 5115, 'n_words': 785}