Skip to content

[#345] Hacky solution to wrong headers resolution - #346

Closed
marcingrzejszczak wants to merge 1 commit into
OpenFeign:masterfrom
marcingrzejszczak:issues_vnd_quick_fix
Closed

marcingrzejszczak wants to merge 1 commit into
OpenFeign:masterfrom
marcingrzejszczak:issues_vnd_quick_fix

Conversation

@marcingrzejszczak

Copy link
Copy Markdown
Contributor

fixes #345

@cloudbees-pull-request-builder

Copy link
Copy Markdown

NetflixOSS » feign » feign-pull-requests #231 SUCCESS
This pull request looks good

@cloudbees-pull-request-builder

Copy link
Copy Markdown

NetflixOSS » feign » feign-pull-requests #232 SUCCESS
This pull request looks good

Collection<String> resolvedValues = new ArrayList<String>();
for (String value : valuesOrEmpty(headers, field)) {
String resolved = urlDecode(expand(value, encoded));
String expandedValueWithEncodedPlus = expand(value, encoded).replaceAll("\\+", "__PLUS__");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

does this do the same thing?

String resolved = urlDecode(expand(value, encoded));
resolved = resolved.replace("%2B", "+"); // special case + as that's commonly used in vnd media types.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually it doesn't. decode just changes + into (space). I thought that it will be exactly what you wrote.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

you mind reader, you :)

nit: I think "replace" doesn't do regex, so you'd not have to escape the "+" iirc. Otherwise, add a comment like " // special case + as that's commonly used in vnd media types." as that helps set hack-context.

@codefromthecrypt

Copy link
Copy Markdown

@ahus1 I think some version of this hack is good enough (I've seen similar things in the past for %20). wdyt?

@marcingrzejszczak
marcingrzejszczak force-pushed the issues_vnd_quick_fix branch 2 times, most recently from f6c9bba to 25b48eb Compare March 8, 2016 15:34
@cloudbees-pull-request-builder

Copy link
Copy Markdown

NetflixOSS » feign » feign-pull-requests #233 SUCCESS
This pull request looks good

@cloudbees-pull-request-builder

Copy link
Copy Markdown

NetflixOSS » feign » feign-pull-requests #234 SUCCESS
This pull request looks good

@ahus1

ahus1 commented Mar 8, 2016

Copy link
Copy Markdown
Contributor

@adriancole @marcingrzejszczak I am fine passing a plus sign "as is".

But instead of doing two replace operations, I would have done one replace operation on the original string of "+" to "%2B".

Otherwise we would get into trouble if someone uses __PLUS__ inside a header.

@marcingrzejszczak

Copy link
Copy Markdown
Contributor Author

hi @ahus1 . I tried that - if I change + to %2B then it gets converted to a space anyways...

String expandedValueWithEncodedPlus = expand(value, encoded).replace("+", "%20"); // special case + as that's commonly used in vnd media types.
        String resolved = urlDecode(expandedValueWithEncodedPlus);

and then in the test you have

java.lang.AssertionError: 
Expecting:
 <{"Accept"=["application/vnd.github.v3 json"], "Host"=["localhost:59024"], "Connection"=["Keep-Alive"], "User-Agent"=["Apache-HttpClient/4.5.1 (Java/1.8.0_45)"], "Accept-Encoding"=["gzip,deflate"]}>
to contain:
 <[MapEntry[key='Accept', value=[application/vnd.github.v3+json]]]>
but could not find:
 <[MapEntry[key='Accept', value=[application/vnd.github.v3+json]]]>

@marcingrzejszczak

Copy link
Copy Markdown
Contributor Author

Argh... instead of %2B I used %20... your suggestion works fine

@cloudbees-pull-request-builder

Copy link
Copy Markdown

NetflixOSS » feign » feign-pull-requests #235 SUCCESS
This pull request looks good

@ahus1

ahus1 commented Mar 8, 2016

Copy link
Copy Markdown
Contributor

As read it you are first expanding, then replacing. I think it should be the other way around, as you don't want to replace any plus coming in from an (encoded) variable?

@marcingrzejszczak

Copy link
Copy Markdown
Contributor Author

Yup - you're right. Fixed it.

@cloudbees-pull-request-builder

Copy link
Copy Markdown

NetflixOSS » feign » feign-pull-requests #236 SUCCESS
This pull request looks good

@ahus1

ahus1 commented Mar 8, 2016

Copy link
Copy Markdown
Contributor

+1 with icing on the top.

@codefromthecrypt

codefromthecrypt commented Mar 9, 2016 via email

Copy link
Copy Markdown

codefromthecrypt pushed a commit that referenced this pull request Mar 9, 2016
I mistakenly advised `@Headers` to follow the encoding rules of `@Body`.
This was a a mistake as in both cases, url encoding is a bad choice, if
the only goal is to prevent accidental variable expansion. For example,
url encoding interferes a lot with content, including messing with '+'
characters, such as exist in "Accept: application/vnd.github.v3+json"

This changes `@Headers` to only address the problem, which where a '{'
literal is desired in a header value. The solution offered here is to
simply repeat "{{" when you desire a '{' literal. For example, if your
header value needs to be literally "{{variable}}", you'd encode it as
"{{{{variable}}".

The impact of this change is limited to those who have already started
using v8.15, and a fast release will occur after merge to limit that.

See #326
Fixes #345
Closes #346
codefromthecrypt pushed a commit that referenced this pull request Mar 9, 2016
I mistakenly advised `@Headers` to follow the encoding rules of `@Body`.
This was a a mistake as in both cases, url encoding is a bad choice, if
the only goal is to prevent accidental variable expansion. For example,
url encoding interferes a lot with content, including messing with '+'
characters, such as exist in "Accept: application/vnd.github.v3+json"

This changes `@Headers` to only address the problem, which where a '{'
literal is desired in a header value. The solution offered here is to
simply repeat "{{" when you desire a '{' literal. For example, if your
header value needs to be literally "{{variable}}", you'd encode it as
"{{{{variable}}".

The impact of this change is limited to those who have already started
using v8.15, and a fast release will occur after merge to limit that.

See #326
Fixes #345
Closes #346
velo pushed a commit that referenced this pull request Oct 8, 2024
I mistakenly advised `@Headers` to follow the encoding rules of `@Body`.
This was a a mistake as in both cases, url encoding is a bad choice, if
the only goal is to prevent accidental variable expansion. For example,
url encoding interferes a lot with content, including messing with '+'
characters, such as exist in "Accept: application/vnd.github.v3+json"

This changes `@Headers` to only address the problem, which where a '{'
literal is desired in a header value. The solution offered here is to
simply repeat "{{" when you desire a '{' literal. For example, if your
header value needs to be literally "{{variable}}", you'd encode it as
"{{{{variable}}".

The impact of this change is limited to those who have already started
using v8.15, and a fast release will occur after merge to limit that.

See #326
Fixes #345
Closes #346
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.

Custom content-types are broken

4 participants