All Downloads are FREE. Search and download functionalities are using the official Maven repository.

scalaz.http.GeneralHeader.scala Maven / Gradle / Ivy

The newest version!
package scalaz
package http

/**
 * HTTP general header fields.
 * RFC 2616 Section 4.5 General Header Fields.
 *
 * @author Tony Morris
 */
sealed trait GeneralHeader {
  /**
   * Returns a string representation of this entity header.
   */
  val asString: String
}
/**
 * §
 */
final case object CacheControl extends GeneralHeader {
  /**
   * A string representation of this general header.
   */
  override val asString = "Cache-Control"
}
/**
 * §
 */
final case object Connection extends GeneralHeader {
  /**
   * A string representation of this general header.
   */
  override val asString = toString
}
/**
 * §
 */
final case object Date extends GeneralHeader {
  /**
   * A string representation of this general header.
   */
  override val asString = toString
}
/**
 * §
 */
final case object Pragma extends GeneralHeader {
  /**
   * A string representation of this general header.
   */
  override val asString = toString
}
/**
 * §
 */
final case object Trailer extends GeneralHeader {
  /**
   * A string representation of this general header.
   */
  override val asString = toString
}
/**
 * §
 */
final case object TransferEncoding extends GeneralHeader {
  /**
   * A string representation of this general header.
   */
  override val asString = "Transfer-Encoding"
}
/**
 * §
 */
final case object Upgrade extends GeneralHeader {
  /**
   * A string representation of this general header.
   */
  override val asString = toString
}
/**
 * §
 */
final case object Via extends GeneralHeader {
  /**
   * A string representation of this general header.
   */
  override val asString = toString
}
/**
 * §
 */
final case object Warning extends GeneralHeader {
  /**
   * A string representation of this general header.
   */
  override val asString = toString
}

trait GeneralHeaders {
  /**
   * Returns a general header for the given list of characters.
   */
  implicit def ListGeneralHeader : (List[Char] => Option[GeneralHeader]) = StringGeneralHeader _ compose (_.mkString)

  /**
   * Returns a string representation for the given general header.
   */
  implicit def GeneralHeaderString(h: GeneralHeader) = h.asString

  /**
   * Returns a general header for the given string.
   */
  implicit def StringGeneralHeader(s: String) = s.toLowerCase match {
    case "cache-control" => Some(CacheControl)
    case "connection" => Some(Connection)
    case "date" => Some(Date)
    case "pragma" => Some(Pragma)
    case "trailer" => Some(Trailer)
    case "transfer-encoding" => Some(TransferEncoding)
    case "upgrade" => Some(Upgrade)
    case "via" => Some(Via)
    case "warning" => Some(Warning)
    case _ => None
  }
}

/**
 * HTTP general header fields.
 * RFC 2616 Section 4.5 General Header Fields.
 */
object GeneralHeader extends GeneralHeaders {
  /**
   * A list of all general entity headers.
   */
  val generalHeaders = List(CacheControl, Connection, Date, Pragma, Trailer, TransferEncoding,
      Upgrade, Via, Warning)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy