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

Headers not sticking #50

Closed
erikthered opened this issue Feb 5, 2016 · 7 comments
Closed

Headers not sticking #50

erikthered opened this issue Feb 5, 2016 · 7 comments
Labels
🐛 bug Something isn't working
Milestone

Comments

@erikthered
Copy link

I don't know if I'm doing something wrong here but I can't seem to get my header changes to stick.

Here's what I'm doing:

Manager.instance.baseHeaders = mapOf(Pair("Content-Type", "application/json"))
val (request, response, data) = url.httpPost(listOf(Pair("emailAddress", email))).responseString()

However, when I debug the Manager class' request method (around line 57) the request's headers are set to:

"Content-Type" -> "application/x-www-form-urlencoded"
"Accept-Encoding" -> "compress;q=0.5, gzip;q=1.0"

This is using just Fuel (not the android lib) in a Spring Boot app with the Kotlin RC

@erikthered
Copy link
Author

I dug a little deeper and it looks like the Encoding class is overriding my headers. Looking at this class it seems that ultimately multipart/form-data and application/x-www-form-urlencoded are the only two Content-Type values that end up being used. Is this the desired behavior?

@kittinunf
Copy link
Owner

I put those 2 as the sane defaults. I anticipated that it would cover most of the case. However, It is true that those 2 values should be configurable. I am sorry for that. I will make some improvements in next coming release.

In the meantime, can you override this at the request level? Meaning that, you could do

url.httpPost(listOf("Content-Type" to "application/json", "emailAddress" to email).responseString() in order to override the defaults

@erikthered
Copy link
Author

@kittinunf I tried that override but Content-Type needs to be a header not a request parameter, so it didn't work.

@kittinunf
Copy link
Owner

Oh I am sorry. What I actually mean is that you can override httpHeader it with header function at request level. url.header("Content-Type" to "application/json").httpPost ....

@kittinunf kittinunf added the 🦄 enhancement Changing current behaviour, enhancing what's already there label Feb 6, 2016
@kittinunf kittinunf added this to the 1.0 Milestone milestone Feb 7, 2016
@kittinunf kittinunf added 🐛 bug Something isn't working and removed 🦄 enhancement Changing current behaviour, enhancing what's already there labels Feb 7, 2016
@kittinunf kittinunf mentioned this issue Feb 7, 2016
@kittinunf
Copy link
Owner

@erikthered I addressed this issue in PR #51. Thanks for reporting this.

I stole your use case to become a test case 💛

https://github.com/kittinunf/Fuel/blob/fix-bugs-and-cleanup/fuel/src/test/kotlin/com/github/kittinunf/fuel/BlockingRequestTest.kt#L198-L213

@erikthered
Copy link
Author

Cool! One other suggestion I would make is to add the request level header function to the readme. I didn't even realize that function was available.

@kittinunf
Copy link
Owner

Agree. I'll do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants