<commit_before>package nl.hsac.fitnesse.fixture.slim;

import fit.exception.FitFailureException;
import freemarker.template.Template;
import nl.hsac.fitnesse.fixture.util.BinaryHttpResponse;
import nl.hsac.fitnesse.fixture.util.HttpResponse;
import nl.hsac.fitnesse.fixture.util.NonValidResponseReceivedException;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.CookieStore;
import org.apache.http.cookie.Cookie;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.cookie.BasicClientCookie;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Base64;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Fixture to make HTTP requests using Slim scripts and/or scenarios.
 */
public class HttpTest extends SlimFixtureWithMap {
    /**
     * Default content type for posts and puts.
     */
    public final static String DEFAULT_POST_CONTENT_TYPE = "application/x-www-form-urlencoded; charset=UTF-8";

    private String downloadBase = new File(filesDir, "downloads").getPath() + "/";
    private final Map<String, Object> headerValues = new LinkedHashMap<>();
    private boolean stopTestOnException = true;
    private boolean storeCookies = false;
    private HttpResponse response = createResponse();
    private String template;
    private boolean explicitContentTypeSet = false;
    private String contentType = DEFAULT_POST_CONTENT_TYPE;
    private String lastUrl = null;
    private String lastMethod = null;
    private boolean throwExceptionOnHttpRequestFailure = false;

    public void setThrowExceptionOnHttpRequestFailure(boolean throwException) {
        throwExceptionOnHttpRequestFailure = throwException;
    }

    public boolean getThrowExceptionOnHttpRequestFailure() {
        return throwExceptionOnHttpRequestFailure;
    }

    /**
     * Sets template to use.
     *
     * @param aTemplate name of template file (relative to 'templates' directory on classpath)
     * @return true if template could be found.
     */
    public boolean template(String aTemplate) {
        boolean result = false;
        Template t = getEnvironment().getTemplate(aTemplate);
        if (t != null) {
            template = aTemplate;
            result = true;
        }
        return result;
    }

    /**
     * Enables content compression support in the current environment (i.e. for the entire test run)
     */
    public void enableCompression() {
        getEnvironment().enableHttpClientCompression();
    }

    /**
     * Disables content compression support in the current environment (i.e. for the entire test run)
     */
    public void disableCompression() {
        getEnvironment().disableHttpClientCompression();
    }

    /**
     * Disables SSL certificate verification in the current environment (i.e. for the entire test run)
     */
    public void disableSSLVerification() {
        getEnvironment().disableHttpClientSSLVerification();
    }

    /**
     * Enables SSL certificate verification in the current environment (i.e. for the entire test run)
     */
    public void enableSSLVerification() {
        getEnvironment().enableHttpClientSSLVerification();
    }

    /**
     * Use SSL trust store for all requests in the current environment (i.e. for the entire test run)
     */
    public void setTrustStore(String trustStore, String password) {
        String trustStoreFile = getFilePathFromWikiUrl(trustStore);
        getEnvironment().getHttpClient().setTrustStore(trustStoreFile, password);
    }

    /**
     * Resets SSL trust store to default in the current environment (i.e. for the entire test run)
     */
    public void clearTrustStore() {
        getEnvironment().getHttpClient().clearTrustStore();
    }

    /**
     * Send client certificate for all requests in the current environment (i.e. for the entire test run)
     */
    public void setClientCertificate(String keyStore, String keyStorePassword, String keyPassword, String alias) {
        String keyStoreFile = getFilePathFromWikiUrl(keyStore);
        getEnvironment().getHttpClient().setClientCertificate(keyStoreFile, keyStorePassword, keyPassword, alias);
    }

    /**
     * No longer send client certificate in the current environment (i.e. for the entire test run)
     */
    public void clearClientCertificate() {
        getEnvironment().getHttpClient().clearClientCertificate();
    }

    /**
     * Stores value to be passed as headers.
     *
     * @param value value to be passed.
     * @param name  name to use this value for.
     */
    public void setValueForHeader(Object value, String name) {
        getMapHelper().setValueForIn(value, name, headerValues);
    }

    /**<commit_msg>Make method names better wiki words better wiki words<commit_after>package nl.hsac.fitnesse.fixture.slim;

import fit.exception.FitFailureException;
import freemarker.template.Template;
import nl.hsac.fitnesse.fixture.util.BinaryHttpResponse;
import nl.hsac.fitnesse.fixture.util.HttpResponse;
import nl.hsac.fitnesse.fixture.util.NonValidResponseReceivedException;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.CookieStore;
import org.apache.http.cookie.Cookie;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.cookie.BasicClientCookie;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Base64;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Fixture to make HTTP requests using Slim scripts and/or scenarios.
 */
public class HttpTest extends SlimFixtureWithMap {
    /**
     * Default content type for posts and puts.
     */
    public final static String DEFAULT_POST_CONTENT_TYPE = "application/x-www-form-urlencoded; charset=UTF-8";

    private String downloadBase = new File(filesDir, "downloads").getPath() + "/";
    private final Map<String, Object> headerValues = new LinkedHashMap<>();
    private boolean stopTestOnException = true;
    private boolean storeCookies = false;
    private HttpResponse response = createResponse();
    private String template;
    private boolean explicitContentTypeSet = false;
    private String contentType = DEFAULT_POST_CONTENT_TYPE;
    private String lastUrl = null;
    private String lastMethod = null;
    private boolean throwExceptionOnHttpRequestFailure = false;

    public void setThrowExceptionOnHttpRequestFailure(boolean throwException) {
        throwExceptionOnHttpRequestFailure = throwException;
    }

    public boolean getThrowExceptionOnHttpRequestFailure() {
        return throwExceptionOnHttpRequestFailure;
    }

    /**
     * Sets template to use.
     *
     * @param aTemplate name of template file (relative to 'templates' directory on classpath)
     * @return true if template could be found.
     */
    public boolean template(String aTemplate) {
        boolean result = false;
        Template t = getEnvironment().getTemplate(aTemplate);
        if (t != null) {
            template = aTemplate;
            result = true;
        }
        return result;
    }

    /**
     * Enables content compression support in the current environment (i.e. for the entire test run)
     */
    public void enableCompression() {
        getEnvironment().enableHttpClientCompression();
    }

    /**
     * Disables content compression support in the current environment (i.e. for the entire test run)
     */
    public void disableCompression() {
        getEnvironment().disableHttpClientCompression();
    }

    /**
     * Disables SSL certificate verification in the current environment (i.e. for the entire test run)
     */
    public void disableSSLVerification() {
        getEnvironment().disableHttpClientSSLVerification();
    }

    /**
     * Enables SSL certificate verification in the current environment (i.e. for the entire test run)
     */
    public void enableSSLVerification() {
        getEnvironment().enableHttpClientSSLVerification();
    }

    /**
     * Use SSL trust store for all requests in the current environment (i.e. for the entire test run)
     */
    public void setTrustStoreWithPassword(String trustStore, String password) {
        String trustStoreFile = getFilePathFromWikiUrl(trustStore);
        getEnvironment().getHttpClient().setTrustStore(trustStoreFile, password);
    }

    /**
     * Resets SSL trust store to default in the current environment (i.e. for the entire test run)
     */
    public void clearTrustStore() {
        getEnvironment().getHttpClient().clearTrustStore();
    }

    /**
     * Send client certificate for all requests in the current environment (i.e. for the entire test run)
     */
    public void setClientCertificateFromWithPasswordKeyPasswordAndAlias(String keyStore, String keyStorePassword, String keyPassword, String alias) {
        String keyStoreFile = getFilePathFromWikiUrl(keyStore);
        getEnvironment().getHttpClient().setClientCertificate(keyStoreFile, keyStorePassword, keyPassword, alias);
    }

    /**
     * No longer send client certificate in the current environment (i.e. for the entire test run)
     */
    public void clearClientCertificate() {
        getEnvironment().getHttpClient().clearClientCertificate();
    }

    /**
     * Stores value to be passed as headers.
     *
     * @param value value to be passed.
     * @param name  name to use this value for.
     */
    public void setValueForHeader(Object value, String name) {
        getMapHelper().setValueForIn(value, name, headerValues);
    }

    /**
{'fraction_non_alphanumeric': 0.08746059188447065, 'fraction_numerical': 0.0008135869012508898, 'mean_word_length': 3.368725011106175, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '3869090', 'n_tokens_mistral': 2584, 'n_tokens_neox': 2547, 'n_words': 756}