Repository: square/okhttp
File: okhttp/src/commonJvmAndroid/kotlin/okhttp3/Request.kt (Kotlin)

Code before:
     * present. If [cacheControl] doesn't define any directives, this clears this request's
     * cache-control headers.
     */
    open fun cacheControl(cacheControl: CacheControl): Builder {
      val value = cacheControl.toString()
      return when {
        value.isEmpty() -> removeHeader("Cache-Control")
        else -> header("Cache-Control", value)
      }
    }

    open fun get(): Builder = method("GET", null)

    open fun head(): Builder = method("HEAD", null)

    open fun post(body: RequestBody): Builder = method("POST", body)

    @JvmOverloads
    open fun delete(body: RequestBody? = RequestBody.EMPTY): Builder = method("DELETE", body)

    open fun put(body: RequestBody): Builder = method("PUT", body)

    open fun patch(body: RequestBody): Builder = method("PATCH", body)

    open fun query(body: RequestBody): Builder = method("QUERY", body)

    open fun method(
      method: String,
      body: RequestBody?,
    ): Builder =
      apply {
        require(method.isNotEmpty()) {
          "method.isEmpty() == true"
        }
        if (body == null) {
          require(!HttpMethod.requiresRequestBody(method)) {
            "method $method must have a request body."
          }
        } else {
          require(HttpMethod.permitsRequestBody(method)) {
            "method $method must not have a request body."
          }
        }
        this.method = method
        this.body = body
      }

    /**
     * Attaches [tag] to the request using [T] as a key. Tags can be read from a request using
     * [Request.tag]. Use null to remove any existing tag assigned for [T].
     *

Review comment (performance):
Could we just require a non-null `cacheUrlOverride` for these?

Code after:
     * present. If [cacheControl] doesn't define any directives, this clears this request's
     * cache-control headers.
     */
    open fun cacheControl(cacheControl: CacheControl): Builder {
      val value = cacheControl.toString()
      return when {
        value.isEmpty() -> removeHeader("Cache-Control")
        else -> header("Cache-Control", value)
      }
    }

    open fun get(): Builder = method("GET", null)

    open fun head(): Builder = method("HEAD", null)

    open fun post(body: RequestBody): Builder = method("POST", body)

    @JvmOverloads
    open fun delete(body: RequestBody? = RequestBody.EMPTY): Builder = method("DELETE", body)

    open fun put(body: RequestBody): Builder = method("PUT", body)

    open fun patch(body: RequestBody): Builder = method("PATCH", body)

    /**
     * A QUERY request with a body. If `body.isOneShot()` is true, then caching will be disabled.
     */
    open fun query(body: RequestBody): Builder = method("QUERY", body)

    open fun method(
      method: String,
      body: RequestBody?,
    ): Builder =
      apply {
        require(method.isNotEmpty()) {
          "method.isEmpty() == true"
        }
        if (body == null) {
          require(!HttpMethod.requiresRequestBody(method)) {
            "method $method must have a request body."
          }
        } else {
          require(HttpMethod.permitsRequestBody(method)) {
            "method $method must not have a request body."
          }
        }
        this.method = method
        this.body = body
      }

    /**