Retrofit: Retrofit 2.4.0 adding new line character at the end of header string

Created on 24 Mar 2018  Â·  15Comments  Â·  Source: square/retrofit

I am using Retrofit v2.4.0, It is adding a new line character in headers which fails my call.

"Authorization: Base dXNlcm5hbWU6cGFzc3dvcmQ=\n"

I have tried static and dynamic headers also interceptors but the result is same.

What is solution for this?

Most helpful comment

I apologize that this software which is entirely open source and provided
to you for no charge that has been worked on by people in their spare time
which promises no support nor provides an SLA of any kind hasn't met your
level of satisfaction and where you were asked for an executable sample or
failing test case such that we could easily reproduce the exact conditions
that you were seeing to quickly diagnose the problem but where you instead
repeatedly commented to draw attention to your issue with neither of those
things and inadequate time periods between them didn't produce the desired
result for you. We remain here to assist you in the future, however.

On Mon, Mar 26, 2018 at 5:11 PM sam notifications@github.com wrote:

Closed #2712 https://github.com/square/retrofit/issues/2712.

—
You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
https://github.com/square/retrofit/issues/2712#event-1541869374, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAEEEbcyGpytO3HGi5yl_GsP9GfkBHruks5tiVl3gaJpZM4S57xv
.

All 15 comments

Please provide a failing test case or executable sample that demonstrates the problem.

@JakeWharton

It's a simple case of adding Headers in the call. Whenever I try adding header it returns 400 and if I remove headers it return 200 and proper response. After digging into the headers in the request i found out that there is a special character of new line as follows.

"Authorization: Base dXNlcm5hbWU6cGFzc3dvcmQ=\n"

Well we have tests that show that we aren't adding newlines so without a failing test case or executable sample I have no way of knowing whether or not your input data contains a trailing newline which I strongly suspect is the underlying cause.

@Headers({
      "Authorization: Basic YWRtaW46YWRtaW4xMjM=",
      "Content-Type: application/json"
})
@POST("/_search")
Call<Response> apiCall(@Body PostBody obj, @Query("q") String keyword);

That's how I am providing header.and there are no trailing newline.

@JakeWharton
also this way as well

@post("/_search")
Call apiCall(@header("Authorization") String authToken, @Body PostBody obj, @query("q") String keyword);

Please see attached screen shots where I have inspected the value. also there is code snippet of the library.

And this is how I am building Retrofit.

Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(BasketUtils.getBaseUrl(BASE_URL_TYPE_LIVE))
                .addConverterFactory(GsonConverterFactory.create())
                .build();

image
image

\n is the trailing whitespace

@vanniktech
yes and if you see the toString method, it is from Headers.java class in Retrofit. Is this causing the real problem?

There is no Headers.java in Retrofit. That's from OkHttp and it's debugging output, not what's put on the wire.

@JakeWharton

I am just making a basic authentication token and passing in header field let me know how to pass header in retrofit header if i am doing wrong in above code.

Thakns,

any body here???

This is not a support forum and Retrofit is not a paid product that
guarantees support. We will look at this potential bug when we have free
time.

On Mon, Mar 26, 2018 at 3:21 PM sam notifications@github.com wrote:

any body here???

—
You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
https://github.com/square/retrofit/issues/2712#issuecomment-376281502,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAEEEQYw97bGPDPBDgIHttuNZ1BATXXCks5tiT-sgaJpZM4S57xv
.

Well that's rude of you man...

I apologize that this software which is entirely open source and provided
to you for no charge that has been worked on by people in their spare time
which promises no support nor provides an SLA of any kind hasn't met your
level of satisfaction and where you were asked for an executable sample or
failing test case such that we could easily reproduce the exact conditions
that you were seeing to quickly diagnose the problem but where you instead
repeatedly commented to draw attention to your issue with neither of those
things and inadequate time periods between them didn't produce the desired
result for you. We remain here to assist you in the future, however.

On Mon, Mar 26, 2018 at 5:11 PM sam notifications@github.com wrote:

Closed #2712 https://github.com/square/retrofit/issues/2712.

—
You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
https://github.com/square/retrofit/issues/2712#event-1541869374, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAEEEbcyGpytO3HGi5yl_GsP9GfkBHruks5tiVl3gaJpZM4S57xv
.

I have the same problem. Any ideas?

The same for me.
It happened with the body, I guess cause problem "=" this symbol

Was this page helpful?
0 / 5 - 0 ratings