Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use URLBuilder instead of Url in mappers and HttpFetcher #78

Open
wants to merge 30 commits into
base: v1.0.0
Choose a base branch
from

Conversation

ayanyev
Copy link

@ayanyev ayanyev commented Dec 4, 2023

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.

@luca992
Copy link
Member

luca992 commented Dec 6, 2023

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

Screenshot 2023-12-06 at 6 08 13 PM

@ayanyev
Copy link
Author

ayanyev commented Dec 7, 2023

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.

@eskatos
Copy link

eskatos commented Jan 23, 2024

Copy link
Member

@luca992 luca992 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ayanyev finally got to take a deeper look at this. I think you're right about using UrlBuilder.... I don't think it's a great idea to fully remove support from ktor Urls though. I think adding a Url to UrlBuilder mapper that's in the default kamel config would be a good idea.

@eskatos https://youtrack.jetbrains.com/issue/KTOR-360 looks like it's relevant. But, who knows when that will be implemented. Probably best to not wait for it

@luca992 luca992 changed the base branch from main to v1.0.0 July 1, 2024 03:10
needed since the string mapper only maps to URLBuilder now
this test just showed that urls didn't merge together correctly with the old HttpUrlFetcher
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants