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

skinny.micro.constant.HttpVersion.scala Maven / Gradle / Ivy

package skinny.micro.constant

/**
 * HTTP protocol version.
 */
abstract class HttpVersion(
  val protocolName: String,
  val majorVersion: Int,
  val minorVersion: Int,
  val keepAliveDefault: Boolean) extends Ordered[HttpVersion] {

  val text: String = protocolName + '/' + majorVersion + '.' + minorVersion

  override def toString: String = text

  override def hashCode(): Int = protocolName.## * 31 + majorVersion.## * 31 + minorVersion

  override def equals(obj: Any): Boolean = obj match {
    case m: HttpVersion =>
      protocolName == m.protocolName &&
        majorVersion == m.majorVersion &&
        minorVersion == m.minorVersion
    case _ => false
  }

  def compare(that: HttpVersion): Int = {
    val v = protocolName.compareTo(that.protocolName)
    if (v != 0) v
    else {
      val vv = majorVersion - that.majorVersion
      if (vv != 0) vv
      else minorVersion - that.minorVersion
    }
  }

}

/**
 * HTTP/1.0
 */
object Http10 extends HttpVersion("HTTP", 1, 0, false)

/**
 * HTTP/1.1
 */
object Http11 extends HttpVersion("HTTP", 1, 1, true)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy