-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(headers): Added an X-Proxy-Cache header
- Loading branch information
Showing
2 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/main/scala/com/imageintelligence/http4c/headers/`X-Proxy-Cache`.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.imageintelligence.http4c.headers | ||
|
||
import scalaz._, Scalaz._ | ||
import org.http4s.util.Writer | ||
import org.http4s.dsl._ | ||
import org.http4s._ | ||
|
||
final case class `X-Proxy-Cache`(cacheHit: Boolean) extends Header.Parsed { | ||
override def key = `X-Proxy-Cache` | ||
override def renderValue(writer: Writer): writer.type = { | ||
if (cacheHit) { | ||
writer.append("HIT") | ||
} else { | ||
writer.append("MISS") | ||
} | ||
} | ||
} | ||
|
||
object `X-Proxy-Cache` extends HeaderKey.Singleton { | ||
type HeaderT = `X-Proxy-Cache` | ||
def name = "X-Proxy-Cache".ci | ||
|
||
def parse(s: String): ParseResult[`X-Proxy-Cache`] = { | ||
s match { | ||
case "HIT" => `X-Proxy-Cache`(true).right | ||
case "MISS" => `X-Proxy-Cache`(false).right | ||
case other => { | ||
val e = s"$other is not a valid X-Proxy-Cache header" | ||
ParseFailure.apply(e, e).left | ||
} | ||
} | ||
} | ||
|
||
def matchHeader(header: Header): Option[`X-Proxy-Cache`] = { | ||
if (header.name == name) | ||
parse(header.value).toOption | ||
else None | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters