I am receiving an html document as a http response...
# server
c
I am receiving an html document as a http response. Is there a way (using ktor or kotlinx html) to parse that response into a document and then extract _csrf from it? I am already using Jsoup for that. but, I want to know if there is another way using kotlinx html or ktor client
a
Ktor, like most HTTP clients, doesn't have a built-in DOM parser. Jsoup is an excellent choice. However you could integrate it via an interceptor so that the extraction of the _csrf value is done transparently. In Ktor this would require a custom plugin that hooks into
onResponse
or maybe
transformResponseBody
. You would still probably use the same Jsoup code but by embedding it into the plugin, it would happen automatically upon every response (or only specified paths/endpoints). In http4k this would be an additional
HttpHandler
in the pipeline. Other clients have the same concept, usually called an "interceptor" or "filter".
c
I'd use JSoup.