Skip to content

Instantly share code, notes, and snippets.

@oharaandrew314
Last active January 24, 2022 03:24
Show Gist options
  • Save oharaandrew314/8a83c87ad71480a003c1781f24663243 to your computer and use it in GitHub Desktop.
Save oharaandrew314/8a83c87ad71480a003c1781f24663243 to your computer and use it in GitHub Desktop.
class FakeThirdPartyImageBackend: HttpHandler {
private var nextId = 0
val images = mutableListOf<ThirdPartyImageDto>()
private fun upload(request: Request): Response {
val id = "image${nextId++}"
val image = ThirdPartyImageDto(
id = id,
contentType = Header.CONTENT_TYPE(request)?.value
?: return Response(Status.BAD_REQUEST).body("no content-type"),
size = request.body.payload.length(),
url = "http://images.fake/$id"
)
images += image
return Response(Status.OK).with(ThirdPartyImageClient.imageBody of image)
}
private val routes = routes(
ThirdPartyImageClient.uploadPath bind Method.POST to ::upload
)
override fun invoke(request: Request) = routes(request)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment