@@ -39,15 +39,14 @@ abstract class EntityResponseGenerator[F[_]](val status: Status) extends Respons
39
39
apply(body, Headers .empty)
40
40
41
41
/** Generate a [[Result ]] that carries the type information */
42
- def apply [A ](body : A , headers : Headers )(implicit F : Monad [F ], w : EntityEncoder [F , A ]): F [T [A ]] =
43
- w.toEntity(body) match {
44
- case Entity (proc, len) =>
45
- val hs = len match {
46
- case Some (l) => (w.headers ++ headers).put(`Content-Length`.unsafeFromLong(l))
47
- case None => w.headers ++ headers
48
- }
49
- F .pure(Result (Response [F ](status = status, headers = hs, body = proc)).asInstanceOf [T [A ]])
42
+ def apply [A ](body : A , headers : Headers )(implicit F : Monad [F ], w : EntityEncoder [F , A ]): F [T [A ]] = {
43
+ val entity = w.toEntity(body)
44
+ val hs = entity.length match {
45
+ case Some (l) => (w.headers ++ headers).put(`Content-Length`.unsafeFromLong(l))
46
+ case None => w.headers ++ headers
50
47
}
48
+ F .pure(Result (Response [F ](status = status, headers = hs, entity = entity)).asInstanceOf [T [A ]])
49
+ }
51
50
52
51
/** Generate wrapper free `Response` */
53
52
def pure [A ](body : A )(implicit F : Monad [F ], w : EntityEncoder [F , A ]): F [Response [F ]] =
@@ -56,15 +55,14 @@ abstract class EntityResponseGenerator[F[_]](val status: Status) extends Respons
56
55
/** Generate wrapper free `Response` */
57
56
def pure [A ](body : A , headers : Headers )(implicit
58
57
F : Monad [F ],
59
- w : EntityEncoder [F , A ]): F [Response [F ]] =
60
- w.toEntity(body) match {
61
- case Entity (proc, len) =>
62
- val hs = len match {
63
- case Some (l) => (w.headers ++ headers).put(`Content-Length`.unsafeFromLong(l))
64
- case None => w.headers ++ headers
65
- }
66
- F .pure(Response (status = status, headers = hs, body = proc))
58
+ w : EntityEncoder [F , A ]): F [Response [F ]] = {
59
+ val entity = w.toEntity(body)
60
+ val hs = entity.length match {
61
+ case Some (l) => (w.headers ++ headers).put(`Content-Length`.unsafeFromLong(l))
62
+ case None => w.headers ++ headers
67
63
}
64
+ F .pure(Response (status = status, headers = hs, entity = entity))
65
+ }
68
66
69
67
}
70
68
@@ -76,15 +74,14 @@ abstract class LocationResponseGenerator[F[_]](val status: Status) extends Respo
76
74
77
75
def apply [A ](location : Uri , body : A , headers : Headers = Headers .empty)(implicit
78
76
F : Monad [F ],
79
- w : EntityEncoder [F , A ]): F [T [A ]] =
80
- w.toEntity(body) match {
81
- case Entity (proc, len) =>
82
- val hs = (len match {
83
- case Some (l) => (w.headers ++ headers).put(`Content-Length`.unsafeFromLong(l))
84
- case None => w.headers ++ headers
85
- }).put(Location (location))
86
- F .pure(Result (Response [F ](status = status, headers = hs, body = proc)).asInstanceOf [T [A ]])
87
- }
77
+ w : EntityEncoder [F , A ]): F [T [A ]] = {
78
+ val entity = w.toEntity(body)
79
+ val hs = (entity.length match {
80
+ case Some (l) => (w.headers ++ headers).put(`Content-Length`.unsafeFromLong(l))
81
+ case None => w.headers ++ headers
82
+ }).put(Location (location))
83
+ F .pure(Result (Response [F ](status = status, headers = hs, entity = entity)).asInstanceOf [T [A ]])
84
+ }
88
85
}
89
86
90
87
trait ResponseGeneratorInstances [F [_]] {
0 commit comments