-
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-6946 headers in the default request are overriding new custom headers #4157
Conversation
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.
@igloo12 Thank you for the PR! I noticed that these changes break some tests in DefaultRequestTest.kt
, and I'm not sure if it's better to change the plugin's behavior. Isn't the next workaround applicable to your case?
defaultRequest {
headers.appendIfNameAbsent(HttpHeaders.ContentType, ContentType.Application.Json.toString())
}
@marychatte, I changed the PR to override only the content type. My logic is the content type set via What do you think? |
@marychatte, could you check? |
As described in the PR, the plugin defaultRequest {
contentType(ContentType.Application.Json) // defaultRequest header
}
val response = client.get("/") {
contentType(ContentType.Application.Xml) // users' header
} The final So, we need to set the user's headers, and also because defaultRequest {
headers.appendIfNameAbsent("header", "value)
} But there is a small problem that some Proposed solution:
|
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
Motivation
I need to override the default headers with custom headers
Solution
The issue is with this code block.
The plugin call is erasing the headers. I reversed the order and added a new method to the builder to replace the ones set by the default block