Kamel icon indicating copy to clipboard operation
Kamel copied to clipboard

Use URLBuilder instead of Url in mappers and HttpFetcher

Open ayanyev opened this issue 2 years ago • 3 comments

There is an issue when full resource url is split between httpClient config and asyncPainterResource call:

defaultRequest {
     url("https://kamel.media")
}
asyncPainterResource("/image.jpg")

If mapper and fetcher use Url respectively as output and input data, the resulting resource url will look like: https://localhost:80/image.jpg

This happens due to DefaultRequest.mergeUrls(...) implementation.

DefaultRequestConfigTest is added.

ayanyev avatar Dec 04 '23 20:12 ayanyev

Does fun URLBuilder.takeFrom(url: Url): URLBuilder not work? (instead of URLBuilder.takeFrom(url: URLBuilder))

Screenshot 2023-12-06 at 6 08 13 PM

luca992 avatar Dec 06 '23 23:12 luca992

The problem is when mapper maps to Url, localhost:80 added to /image.jpg with applyOrigin().

    public fun build(): Url {
        applyOrigin()
        return Url(
            protocol = protocol,
            host = host,

When it comes to DefaultRequest.mergeUrls(), execution is stopped at the very beginning because host is not empty.

        private fun mergeUrls(baseUrl: Url, requestUrl: URLBuilder) {
            if (requestUrl.protocol == URLProtocol.HTTP) {
                requestUrl.protocol = baseUrl.protocol
            }
            if (requestUrl.host.isNotEmpty()) return

It ends up fetching image from localhost.

ayanyev avatar Dec 07 '23 07:12 ayanyev

This might be related to the upstream ktor issues

  • https://github.com/ktorio/ktor/issues/1903
  • https://youtrack.jetbrains.com/issue/KTOR-360

eskatos avatar Jan 23 '24 22:01 eskatos