Last active
January 24, 2022 03:24
-
-
Save oharaandrew314/8a83c87ad71480a003c1781f24663243 to your computer and use it in GitHub Desktop.
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
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