scalaz.http.response.StatusLine.scala Maven / Gradle / Ivy
The newest version!
package scalaz
package http
package response
import Scalaz._
/**
* HTTP response status line.
* RFC 2616 Section 6.1 Status-Line.
*
* @author Tony Morris
*/
sealed trait StatusLine {
/**
* The HTTP version in the status line. This is typically HTTP 1.0 or 1.1.
*/
val version: Version
/**
* The response status code.
*/
val status: Status
/**
* The reason phrase for the status code.
*/
val reasonPhrase: List[Char]
}
import request.Request
import Version.version
import Scalaz._
/**
* HTTP response status line.
* RFC 2616 Section 6.1 Status-Line.
*
* @author Tony Morris
*/
object StatusLine {
/**
* Create a status line with the given version, status and reason phrase.
*/
def statusLine(v: Version, s: Status, r: List[Char]) = new StatusLine {
val version = v
val status = s
val reasonPhrase = r
}
/**
* Create a status line with the given version, status and a reason phrase derived from the status if it has one
* associated. RFC 2616 Section 6.1.1 Status Code and Reason Phrase.
*/
def statusLine(version: Version, status: Status): StatusLine = statusLine(version, status, status.reasonPhrase | Nil)
/**
* Create a status line with the given status, a version derived from the given request and a reason phrase
* derived from the status if it has one associated.
* RFC 2616 Section 6.1.1 Status Code and Reason Phrase.
*/
def statusLine[IN[_]](status: Status)(implicit req: Request[IN]): StatusLine = statusLine(req.line.version, status)
/**
* Create a status line with the given status, a HTTP/1.0 version and a reason phrase derived from the status
* if it has one associated.
* RFC 2616 Section 6.1.1 Status Code and Reason Phrase.
*/
import Digit._
implicit def statusLine10(status: Status) = statusLine(version(_1, _0), status)
/**
* Create a status line with the given status, a HTTP/1.1 version and a reason phrase derived from the status
* if it has one associated.
* RFC 2616 Section 6.1.1 Status Code and Reason Phrase.
*/
implicit def statusLine11(status: Status) = statusLine(version(_1, _1), status)
}