<commit_before>package protocols

import akka.NotUsed
import akka.stream.scaladsl.Source
import models.cfs.Block._
import play.api.http._
import play.api.libs.MimeTypes
import play.api.mvc._
import play.utils.UriEncoding

/**
 * @author <EMAIL>
 */

trait HttpDownloadable {

  def size: Long
  def name: String
  def whole: Source[BLK, NotUsed]
}

trait HttpDownloadResult extends HeaderNames with Status {

  def send(
    file: HttpDownloadable,
    name: HttpDownloadable => String = _.name,
    inline: Boolean = false
  ): Result = {
    val result = Result(
      ResponseHeader(OK),
      HttpEntity.Streamed(
        file.whole,
        Some(file.size),
        contentTypeOf(file)
      )
    )
    if (inline) result
    else {
      val encoded = UriEncoding.encodePathSegment(name(file), "utf-8")
      result.withHeaders(
        CONTENT_DISPOSITION -> s"""attachment; filename="$encoded" """
      )
    }
  }

  def contentTypeOf(inode: HttpDownloadable): Option[String] = {
    MimeTypes.forFileName(inode.name).orElse(Some(ContentTypes.BINARY))
  }
}

object HttpDownloadResult extends HttpDownloadResult<commit_msg>Support non-ISO8859-1 filename in Content-Disposition header<commit_after>package protocols

import java.nio.charset.StandardCharsets

import akka.NotUsed
import akka.stream.scaladsl.Source
import models.cfs.Block._
import play.api.http._
import play.api.libs.MimeTypes
import play.api.mvc._
import play.utils.UriEncoding

/**
 * @author <EMAIL>
 */

trait HttpDownloadable {

  def size: Long
  def name: String
  def whole: Source[BLK, NotUsed]
}

trait HttpDownloadResult extends HeaderNames with Status {

  def send(
    file: HttpDownloadable,
    name: HttpDownloadable => String = _.name,
    inline: Boolean = false
  ): Result = {
    val result = Result(
      ResponseHeader(OK),
      HttpEntity.Streamed(
        file.whole,
        Some(file.size),
        contentTypeOf(file)
      )
    )
    val encoded = UriEncoding.encodePathSegment(name(file), StandardCharsets.UTF_8)
    result.withHeaders(
      CONTENT_DISPOSITION -> {
        val dispositionType = if (inline) "inline" else "attachment"
        s"""$dispositionType; filename="$name"; filename*=utf-8''$encoded"""
      }
    )
  }

  def contentTypeOf(inode: HttpDownloadable): Option[String] = {
    MimeTypes.forFileName(inode.name).orElse(Some(ContentTypes.BINARY))
  }
}

object HttpDownloadResult extends HttpDownloadResult
{'fraction_non_alphanumeric': 0.1069672131147541, 'fraction_numerical': 0.003278688524590164, 'mean_word_length': 3.438181818181818, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2884893', 'n_tokens_mistral': 767, 'n_tokens_neox': 745, 'n_words': 164}