<commit_before>package org.http4s
package client

import cats._
import cats.data.{Kleisli, OptionT}
import cats.effect._
import cats.implicits._
import fs2._
import java.io.IOException
import java.util.concurrent.atomic.AtomicBoolean
import org.http4s.Status.Successful
import org.http4s.headers.{Accept, MediaRangeAndQValue}
import scala.concurrent.SyncVar
import scala.util.control.NoStackTrace
import org.log4s.getLogger

/**
  * Contains a [[Response]] that needs to be disposed of to free the underlying
  * HTTP connection.
  * @param response
  * @param dispose
  */
final case class DisposableResponse[F[_]](response: Response[F], dispose: F[Unit]) {

  private[this] val logger = getLogger

  /**
    * Returns a task to handle the response, safely disposing of the underlying
    * HTTP connection when the task finishes.
    */
  def apply[A](f: Response[F] => F[A])(implicit F: MonadError[F, Throwable]): F[A] = {
    //Catch possible user bugs in pure expression
    val task: F[A] = try f(response)
    catch {
      case e: Throwable =>
        logger.info(s"Caught exception in otherwise pure expression $e")
        F.raiseError(e)
    }

    for {
      result <- task.attempt
      _ <- dispose
      fold <- result.fold[F[A]](F.raiseError, F.pure)
    } yield fold
  }
}

/**
  * A [[Client]] submits [[Request]]s to a server and processes the [[Response]].
  *
  * @param open a service to asynchronously return a [[DisposableResponse]] from
  *             a [[Request]].  This is a low-level operation intended for client
  *             implementations and middleware.
  *
  * @param shutdown an effect to shut down this Shutdown this client, closing any
  *                 open connections and freeing resources
  */
final case class Client[F[_]](<commit_msg>lecture harder<commit_after>package org.http4s
package client

import cats._
import cats.data.{Kleisli, OptionT}
import cats.effect._
import cats.implicits._
import fs2._
import java.io.IOException
import java.util.concurrent.atomic.AtomicBoolean
import org.http4s.Status.Successful
import org.http4s.headers.{Accept, MediaRangeAndQValue}
import scala.concurrent.SyncVar
import scala.util.control.NoStackTrace
import org.log4s.getLogger

/**
  * Contains a [[Response]] that needs to be disposed of to free the underlying
  * HTTP connection.
  * @param response
  * @param dispose
  */
final case class DisposableResponse[F[_]](response: Response[F], dispose: F[Unit]) {

  private[this] val logger = getLogger

  /**
    * Returns a task to handle the response, safely disposing of the underlying
    * HTTP connection when the task finishes.
    */
  def apply[A](f: Response[F] => F[A])(implicit F: MonadError[F, Throwable]): F[A] = {
    //Catch possible user bugs in pure expression
    val task: F[A] = try f(response)
    catch {
      case e: Throwable =>
        logger.error(s"Caught exception in otherwise pure expression $e")
        F.raiseError(e)
    }

    for {
      result <- task.attempt
      _ <- dispose
      fold <- result.fold[F[A]](F.raiseError, F.pure)
    } yield fold
  }
}

/**
  * A [[Client]] submits [[Request]]s to a server and processes the [[Response]].
  *
  * @param open a service to asynchronously return a [[DisposableResponse]] from
  *             a [[Request]].  This is a low-level operation intended for client
  *             implementations and middleware.
  *
  * @param shutdown an effect to shut down this Shutdown this client, closing any
  *                 open connections and freeing resources
  */
final case class Client[F[_]](
{'fraction_non_alphanumeric': 0.10582306830907055, 'fraction_numerical': 0.002799552071668533, 'mean_word_length': 3.2334123222748814, 'pattern_counts': {'":': 0, '<': 9, '<?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': '2136451', 'n_tokens_mistral': 1091, 'n_tokens_neox': 1056, 'n_words': 350}