<commit_before>package org.rackspace.deproxy


class DefaultClientConnector extends BareClientConnector {

    public DefaultClientConnector() {
        this(null)
    }
    public DefaultClientConnector(Socket socket) {
        super(socket)
    }

    @Override
    Response sendRequest(Request request, boolean https, host, port, RequestParams params) {

        if (params.sendDefaultRequestHeaders) {

            if (request.body) {

                if (params.usedChunkedTransferEncoding) {

                    if (!request.headers.contains("Transfer-Encoding")) {
                        request.headers.add("Transfer-Encoding", "chunked")
                    }

                } else if (!request.headers.contains("Transfer-Encoding") ||
                            request.headers["Transfer-Encoding"] == "identity") {

                    def length
                    String contentType
                    if (request.body instanceof String) {
                        length = request.body.length()
                        contentType = "text/plain"
                    } else if (request.body instanceof byte[]) {
                        length = request.body.length
                        contentType = "application/octet-stream"
                    } else {
                        throw new UnsupportedOperationException("Unknown data type in requestBody")
                    }

                    if (length > 0) {
                        if (!request.headers.contains("Content-Length")) {
                            request.headers.add("Content-Length", length)
                        }
                        if (!request.headers.contains("Content-Type")) {
                            request.headers.add("Content-Type", contentType)
                        }
                    }
                }<commit_msg>Treat strings explicitly as ascii byte sequences when calculating Content-Length. Don't rely on character count.<commit_after>package org.rackspace.deproxy


class DefaultClientConnector extends BareClientConnector {

    public DefaultClientConnector() {
        this(null)
    }
    public DefaultClientConnector(Socket socket) {
        super(socket)
    }

    @Override
    Response sendRequest(Request request, boolean https, host, port, RequestParams params) {

        if (params.sendDefaultRequestHeaders) {

            if (request.body) {

                if (params.usedChunkedTransferEncoding) {

                    if (!request.headers.contains("Transfer-Encoding")) {
                        request.headers.add("Transfer-Encoding", "chunked")
                    }

                } else if (!request.headers.contains("Transfer-Encoding") ||
                            request.headers["Transfer-Encoding"] == "identity") {

                    def length
                    String contentType
                    if (request.body instanceof String) {
                        length = request.body.getBytes("US-ASCII").length()
                        contentType = "text/plain"
                    } else if (request.body instanceof byte[]) {
                        length = request.body.length
                        contentType = "application/octet-stream"
                    } else {
                        throw new UnsupportedOperationException("Unknown data type in requestBody")
                    }

                    if (length > 0) {
                        if (!request.headers.contains("Content-Length")) {
                            request.headers.add("Content-Length", length)
                        }
                        if (!request.headers.contains("Content-Type")) {
                            request.headers.add("Content-Type", contentType)
                        }
                    }
                }
{'fraction_non_alphanumeric': 0.08942661756970016, 'fraction_numerical': 0.0005260389268805891, 'mean_word_length': 1.376875, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '533339', 'n_tokens_mistral': 846, 'n_tokens_neox': 780, 'n_words': 170}