<commit_before>/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package khttp.requests

import khttp.structures.authorization.Authorization
import khttp.structures.parameters.Parameters
import org.json.JSONArray
import org.json.JSONObject
import org.json.JSONWriter
import java.io.StringWriter
import java.net.IDN
import java.net.URI
import java.net.URL

class GenericRequest internal constructor(
    override val method: String,
    url: String,
    override val params: Map<String, String>,
    headers: Map<String, String>,
    data: Any?,
    override val json: Any?,
    override val auth: Authorization?,
    override val cookies: Map<String, String>?,
    override val timeout: Double,
    allowRedirects: Boolean?
) : Request {

    companion object {
        val DEFAULT_HEADERS = mapOf(
            "Accept" to "*/*",
            "Accept-Encoding" to "gzip, deflate",
            "User-Agent" to "khttp/1.0.0-SNAPSHOT"
        )
        val DEFAULT_DATA_HEADERS = mapOf(
            "Content-Type" to "text/plain"
        )
        val DEFAULT_FORM_HEADERS = mapOf(
            "Content-Type" to "application/x-www-form-urlencoded"
        )
        val DEFAULT_JSON_HEADERS = mapOf(
            "Content-Type" to "application/json"
        )
    }

    // Request
    override val url: String
    override val headers: Map<String, String>
    override val data: Any?
    override val allowRedirects = allowRedirects ?: this.method != "HEAD"

    init {
        this.url = this.makeRoute(url)
        if (URI(this.url).scheme !in setOf("http", "https")) {
            throw IllegalArgumentException("Invalid schema. Only http:// and https:// are supported.")
        }
        val json = this.json
        val mutableHeaders = headers.toLinkedMap()
        if (json == null) {
            this.data = data
            if (data != null) {
                mutableHeaders += GenericRequest.DEFAULT_DATA_HEADERS
            }
        } else {
            this.data = this.coerceToJSON(json)
            mutableHeaders += GenericRequest.DEFAULT_JSON_HEADERS
        }
        for ((key, value) in GenericRequest.DEFAULT_HEADERS) {
            if (key !in mutableHeaders) {
                mutableHeaders[key] = value
            }
        }
        if (this.data is Map<*, *>) {
            mutableHeaders += GenericRequest.DEFAULT_FORM_HEADERS
        }
        val auth = this.auth
        if (auth != null) {<commit_msg>Fixed: Apparently parentheses are important<commit_after>/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package khttp.requests

import khttp.structures.authorization.Authorization
import khttp.structures.parameters.Parameters
import org.json.JSONArray
import org.json.JSONObject
import org.json.JSONWriter
import java.io.StringWriter
import java.net.IDN
import java.net.URI
import java.net.URL

class GenericRequest internal constructor(
    override val method: String,
    url: String,
    override val params: Map<String, String>,
    headers: Map<String, String>,
    data: Any?,
    override val json: Any?,
    override val auth: Authorization?,
    override val cookies: Map<String, String>?,
    override val timeout: Double,
    allowRedirects: Boolean?
) : Request {

    companion object {
        val DEFAULT_HEADERS = mapOf(
            "Accept" to "*/*",
            "Accept-Encoding" to "gzip, deflate",
            "User-Agent" to "khttp/1.0.0-SNAPSHOT"
        )
        val DEFAULT_DATA_HEADERS = mapOf(
            "Content-Type" to "text/plain"
        )
        val DEFAULT_FORM_HEADERS = mapOf(
            "Content-Type" to "application/x-www-form-urlencoded"
        )
        val DEFAULT_JSON_HEADERS = mapOf(
            "Content-Type" to "application/json"
        )
    }

    // Request
    override val url: String
    override val headers: Map<String, String>
    override val data: Any?
    override val allowRedirects = allowRedirects ?: (this.method != "HEAD")

    init {
        this.url = this.makeRoute(url)
        if (URI(this.url).scheme !in setOf("http", "https")) {
            throw IllegalArgumentException("Invalid schema. Only http:// and https:// are supported.")
        }
        val json = this.json
        val mutableHeaders = headers.toLinkedMap()
        if (json == null) {
            this.data = data
            if (data != null) {
                mutableHeaders += GenericRequest.DEFAULT_DATA_HEADERS
            }
        } else {
            this.data = this.coerceToJSON(json)
            mutableHeaders += GenericRequest.DEFAULT_JSON_HEADERS
        }
        for ((key, value) in GenericRequest.DEFAULT_HEADERS) {
            if (key !in mutableHeaders) {
                mutableHeaders[key] = value
            }
        }
        if (this.data is Map<*, *>) {
            mutableHeaders += GenericRequest.DEFAULT_FORM_HEADERS
        }
        val auth = this.auth
        if (auth != null) {
{'fraction_non_alphanumeric': 0.10076775431861804, 'fraction_numerical': 0.002687140115163148, 'mean_word_length': 2.238657551274083, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '3100481', 'n_tokens_mistral': 1481, 'n_tokens_neox': 1458, 'n_words': 420}