<commit_before>package com.rackspace.deproxy

import spock.lang.Specification
import spock.lang.Unroll


class DefaultClientConnectorTest extends Specification {

    void testConstructorWithSocketParameter() {

        given: "a DefaultClientConnector using a dummy nextConnector"
        Request capturedRequest = null
        def clientConnector =
                new DefaultClientConnector([
                        'sendRequest': { request, https, host, port, params ->
                            capturedRequest = request;
                            return new Response(200)
                        }] as ClientConnector)

        and: "a simple request"
        Request request = new Request("GET", "/")



        when: "we send the request through the connector"
        RequestParams params = new RequestParams()
        Response response = clientConnector.sendRequest(request, false, "localhost", 80, params)

        then: "it formats the request correctly and includes the standard default request parameters"
        capturedRequest.method == 'GET'
        capturedRequest.path == '/'
        capturedRequest.headers.size() == 4
        capturedRequest.headers.contains("Host")
        capturedRequest.headers["Host"] == "localhost"
        capturedRequest.headers.contains("Accept")
        capturedRequest.headers["Accept"] == "*/*"
        capturedRequest.headers.contains("Accept-Encoding")
        capturedRequest.headers["Accept-Encoding"] == "identity, gzip, compress, deflate, *;q=0"
        capturedRequest.headers.contains("User-Agent")
        capturedRequest.headers["User-Agent"] == Deproxy.VERSION_STRING
        capturedRequest.body == "" || capturedRequest.body == null
        response.code == "200"
    }

    @Unroll("when we call sendRequest with https=#https, #host, and #port, we should get Host: #expectedValue")
    void testHostHeader() {

        given: "a DefaultClientConnector using a dummy nextConnector"
        Request capturedRequest = null
        def clientConnector =
                new DefaultClientConnector([
                        'sendRequest': { request, https, host, port, params ->
                            capturedRequest = request;
                            return new Response(200)
                        }] as ClientConnector)

        and: "a simple request and basic request params"<commit_msg>Fix the method names.<commit_after>package com.rackspace.deproxy

import spock.lang.Specification
import spock.lang.Unroll


class DefaultClientConnectorTest extends Specification {

    void "when we call sendRequest, we should get the standard default request headers"() {

        given: "a DefaultClientConnector using a dummy nextConnector"
        Request capturedRequest = null
        def clientConnector =
                new DefaultClientConnector([
                        'sendRequest': { request, https, host, port, params ->
                            capturedRequest = request;
                            return new Response(200)
                        }] as ClientConnector)

        and: "a simple request"
        Request request = new Request("GET", "/")



        when: "we send the request through the connector"
        RequestParams params = new RequestParams()
        Response response = clientConnector.sendRequest(request, false, "localhost", 80, params)

        then: "it formats the request correctly and includes the standard default request parameters"
        capturedRequest.method == 'GET'
        capturedRequest.path == '/'
        capturedRequest.headers.size() == 4
        capturedRequest.headers.contains("Host")
        capturedRequest.headers["Host"] == "localhost"
        capturedRequest.headers.contains("Accept")
        capturedRequest.headers["Accept"] == "*/*"
        capturedRequest.headers.contains("Accept-Encoding")
        capturedRequest.headers["Accept-Encoding"] == "identity, gzip, compress, deflate, *;q=0"
        capturedRequest.headers.contains("User-Agent")
        capturedRequest.headers["User-Agent"] == Deproxy.VERSION_STRING
        capturedRequest.body == "" || capturedRequest.body == null
        response.code == "200"
    }

    @Unroll
    void "when we call sendRequest with https=#https, #host, and #port, we should get Host: #expectedValue"() {

        given: "a DefaultClientConnector using a dummy nextConnector"
        Request capturedRequest = null
        def clientConnector =
                new DefaultClientConnector([
                        'sendRequest': { request, https, host, port, params ->
                            capturedRequest = request;
                            return new Response(200)
                        }] as ClientConnector)

        and: "a simple request and basic request params"
{'fraction_non_alphanumeric': 0.09178541492036882, 'fraction_numerical': 0.005448449287510477, 'mean_word_length': 2.3660084626234132, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '7251317', 'n_tokens_mistral': 1122, 'n_tokens_neox': 1113, 'n_words': 323}