All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pl.allegro.tech.servicemesh.envoycontrol.config.envoy.ResponseWithBody.kt Maven / Gradle / Ivy

There is a newer version: 0.22.1
Show newest version
package pl.allegro.tech.servicemesh.envoycontrol.config.envoy

import com.fasterxml.jackson.databind.ObjectMapper
import okhttp3.Response
import pl.allegro.tech.servicemesh.envoycontrol.config.service.EchoContainer

data class ResponseWithBody(val response: Response) {

    companion object {
        private val objectMapper by lazy { ObjectMapper() }
    }

    val body = response.body?.string() ?: ""

    fun isFrom(echoContainer: EchoContainer) = body.contains(echoContainer.response)
    fun isOk() = response.isSuccessful
    fun bodyJsonField(field: String) = objectMapper.readTree(body).at(field)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy