Elisabeth,
how about something like this (untested):
case class TimeHeader(nanos: Long) extends HttpHeader {
def name = “Time"
def value = nanos.toString
def lowercaseName = “time"
}
val timedSendReceive: SendReceive = {
val transport: SendReceive = sendReceive
request => {
val timeStamp = System.nanoTime
transport(request) map { response =>
val timeHeader = TimeHeader(System.nanoTime - timeStamp)
response.mapHeaders(timeHeader :: _)
}
}
}
Then you can use the `timedSendReceive` exactly like the pre-defined `sendReceive`.
With the difference that all responses now also contain a `TimeHeader` with the time it took to complete the request.
Cheers,
Mathias
---
mat...@spray.io
http://spray.io
Elisabeth,
how about something like this (untested):
case class TimeHeader(nanos: Long) extends HttpHeader {
def name = “Time"
def value = nanos.toString
def lowercaseName = “time"
}
val timedSendReceive: SendReceive = {
val transport: SendReceive = sendReceive
request => {
val timeStamp = System.nanoTime
transport(request) map { response =>
val timeHeader = TimeHeader(System.nanoTime - timeStamp)
response.mapHeaders(timeHeader :: _)
}
}
}
Then you can use the `timedSendReceive` exactly like the pre-defined `sendReceive`.
With the difference that all responses now also contain a `TimeHeader` with the time it took to complete the request.
Cheers,
Mathias
---
mat...@spray.io
http://spray.io
On 6.3.2015, at 12:46, Elisabeth Anderson
Ah, right, sorry.
This should work:
def render[R <: Rendering](r: R) = r ~~ name ~~ “: “ ~~ value
Cheers,
Mathias
---
mat...@spray.io
http://spray.io
Sure. That works as well.
Rendering of your `Time` header is not that big an issue anyway, since you only want to use that header as a vehicle for transporting the `nanos` values
(rather that is being a header type that should actually be rendered into a request or response).
Cheers,
Mathias
---
mat...@spray.io
http://spray.io