Skip to content

Commit

Permalink
Keep original request body as Array[Byte]
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksei Shashev authored and danslapman committed May 7, 2024
1 parent c86339a commit 0ca82de
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,9 @@ package object admin {
.summary("Test HTTP stub resolution")
.in(execInput)
.in(
binaryBody(RawBodyType.ByteArrayBody)[Option[String]]
.map[RequestBody]((_: Option[String]).fold[RequestBody](AbsentRequestBody)(SimpleRequestBody(_)))(
SimpleRequestBody.subset.getOption(_).map(_.value)
)
byteArrayBody.map[RequestBody]((b: Array[Byte]) => if (b.isEmpty) AbsentRequestBody else SimpleRequestBody(b))(
SimpleRequestBody.subset.getOption(_).map(_.binary).getOrElse(Array.empty)
)
)
.out(jsonBody[SID[HttpStub]])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@ package object exec {
baseEndpoint
.in(execInput)
.in(
binaryBody(RawBodyType.ByteArrayBody)[Option[String]]
.map[RequestBody]((_: Option[String]).fold[RequestBody](AbsentRequestBody)(SimpleRequestBody(_)))(
SimpleRequestBody.subset.getOption(_).map(_.value)
)
byteArrayBody.map[RequestBody]((b: Array[Byte]) => if (b.isEmpty) AbsentRequestBody else SimpleRequestBody(b))(
SimpleRequestBody.subset.getOption(_).map(_.binary).getOrElse(Array.empty)
)
)
.out(headers)
.out(statusCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ case object AbsentRequestBody extends RequestBody {
implicit val absentRequestBodyLoggable: Loggable[AbsentRequestBody.type] = Loggable.empty[AbsentRequestBody.type]
}

final case class SimpleRequestBody(value: String) extends RequestBody
final case class SimpleRequestBody(binary: Array[Byte]) extends RequestBody {
val value: String = new String(binary)
}
object SimpleRequestBody {
final val subset: Subset[RequestBody, SimpleRequestBody] = GenSubset[RequestBody, SimpleRequestBody]

Expand Down

0 comments on commit 0ca82de

Please sign in to comment.