-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
KTOR-7722 content negotiation client accept header control #4462
KTOR-7722 content negotiation client accept header control #4462
Conversation
Thank you for the pull request! @marychatte, could you take a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the idea! I think it's better to introduce a new method exclude(contentType)
instead. So it will look like:
install(ContentNegotiation) {
register(ContentType.Application.Json, TestContentConverter())
}
client.get("https://test.com/") {
accept(ContentType.Application.Pdf)
exclude(ContentType.Application.Json)
}
@marychatte I can do that. However, it seems like that change could be made in addition to the changes I have already made rather than instead of. It would still seem useful to be able to set the default q-value, as well as the change to not add a duplicate accept type in the presence of an existing one with different parameters. Thoughts? |
I'd say adding the same content type with parameters should simply replace the default one. |
Correct. Keeping the content type and adding the same content type with parameters is what the existing code does, and one of the items fixed by my PR. So therefore it seems like we agree this change should be made. The other change that is in the PR so far is the ability to set a default q value for the registered content types. Which I think is also useful. But less so than the ability to override parameters. |
@marychatte I've added the |
Allow accept types to be excluded per request.
b58d0bc
to
86f4988
Compare
Couldn't this be solved by adding a "q" value to the default content type? install(ContentNegotiation) {
register(ContentType.Application.Json.withParameter("q", "0.8"), TestContentConverter())
} However I agree it might look weird. |
I thought about that, but there were a couple of reasons I didn't go with that approach. First, the value that is passed to Second, most people don't call the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rocketraman Thanks for the changes! I wrote some comments, but the general idea is good
@osipxd What do you think about the name defaultAcceptHeaderQValue
?
...ntent-negotiation/common/src/io/ktor/client/plugins/contentnegotiation/ContentNegotiation.kt
Outdated
Show resolved
Hide resolved
...ntent-negotiation/common/src/io/ktor/client/plugins/contentnegotiation/ContentNegotiation.kt
Outdated
Show resolved
Hide resolved
...ntent-negotiation/common/src/io/ktor/client/plugins/contentnegotiation/ContentNegotiation.kt
Outdated
Show resolved
Hide resolved
...ntent-negotiation/common/src/io/ktor/client/plugins/contentnegotiation/ContentNegotiation.kt
Outdated
Show resolved
Hide resolved
...ntent-negotiation/common/src/io/ktor/client/plugins/contentnegotiation/ContentNegotiation.kt
Outdated
Show resolved
Hide resolved
I think it's a bug in the code, and it should be: val matcher = when {
contentType.match(ContentType.Application.Json) -> JsonContentTypeMatcher
else -> defaultMatcher(contentType)
} Can we fix it in this PR as well? |
ff8b735
to
c317d12
Compare
@marychatte Thanks for the review. I've pushed 3 additional commits. |
…/KTOR-7722-content-negotiation-accept-header-control
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Subsystem
Client, ContentNegotiation
Motivation
See https://youtrack.jetbrains.com/issue/KTOR-7722/ContentNegotiation-client-plugin-no-way-to-opt-out-of-Accept-on-a-per-request-basis.
Solution
Implement the two recommendations outlined in the previous issue.