Skip to content

make replacements header values work like in the body - #326

Merged
codefromthecrypt merged 1 commit into
OpenFeign:masterfrom
ahus1:allow_any_replacement_in_header_288
Feb 15, 2016
Merged

codefromthecrypt merged 1 commit into
OpenFeign:masterfrom
ahus1:allow_any_replacement_in_header_288

Conversation

@ahus1

@ahus1 ahus1 commented Feb 10, 2016

Copy link
Copy Markdown
Contributor

This tries to make replacement work in the headers like it works in the body. See #288 for a discussion. You might need to URL-encode literal values for { or % in your existing code.

Old behaviour:

      @Headers("Authorization: {bearer}"
      // will replace -> Authorization: 37dahdbcpadf

      @Headers("Authorization: Bearer {bearer}")
      // will not replace -> Authorization: Bearer {bearer}

      @Headers("Authorization: Bearer %7Bbearer%7B")
      // will not url decode -> Authorization: Bearer %7Bbearer%7B

      @Headers("Authorization: %25"
      // will not url decode -> Authorization: %25````

New behavior

      @Headers("Authorization: {bearer}"
      // will replace (AS BEFORE) -> Authorization: 37dahdbcpadf

      @Headers("Authorization: Bearer {bearer}")
      // WILL replace -> Authorization: Bearer 37dahdbcpadf

      @Headers("Authorization: %7Bbearer%7B"
      // WILL url decode-> Authorization: Bearer {bearer}

      @Headers("Authorization: %25"
      // WILL url decode -> Authorization: %

I've also added some test cases. This PR describes the behaviour I was expecting when using Headers for the first time. But it might be a breaking change for existing users, especially that curly braces now need to encoded if used literally.

Please feel free to comment and discuss, I will update the PR as necessary

@cloudbees-pull-request-builder

Copy link
Copy Markdown

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

@ahus1

ahus1 commented Feb 10, 2016

Copy link
Copy Markdown
Contributor Author

Please first comment on this PR. Reading through more tickets I will probably need to update Contract.processAnnotationsOnParameter() as well...

@cloudbees-pull-request-builder

Copy link
Copy Markdown

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

@ahus1

ahus1 commented Feb 10, 2016

Copy link
Copy Markdown
Contributor Author

... Contract.processAnnotationsOnParameter() now updated as well.

Comment thread core/src/main/java/feign/Contract.java Outdated
return false;
}

private static <K, V> boolean searchMapValuesAny(Map<K, Collection<String>> map, String search) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

s/Any/ContainsSubstring?

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.

will do

@codefromthecrypt

Copy link
Copy Markdown

Don't expect a failure, but can you verify one of your tests cover params on a type?

Otherwise, LGTM nice work!

@ahus1

ahus1 commented Feb 10, 2016

Copy link
Copy Markdown
Contributor Author

I am not sure what you mean by "params on a type". When you provide a code snippet to explain this to me, I am happy to provide a test.

@codefromthecrypt

Copy link
Copy Markdown

I meant to say Headers on type.. like this: https://github.com/Netflix/feign/blob/master/benchmark/src/main/java/feign/benchmark/FeignTestInterface.java#L11

PS update the changelog when this is all ready.. let's make this a minor bump

@codefromthecrypt

Copy link
Copy Markdown

@ahus1 if you're not available for polish by tomorrow, I will do ^^ on the way in. I like to keep the PR queue clean.

@cloudbees-pull-request-builder

Copy link
Copy Markdown

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

@ahus1

ahus1 commented Feb 12, 2016

Copy link
Copy Markdown
Contributor Author

@adriancole I've pushed my polished changes, please feed free to polish/change when needed. All tests are green, but I would have liked to do some canary testing .-)

Comment thread CHANGELOG.md Outdated
@@ -1,5 +1,35 @@
### Version 8.15
* Supports PUT without a body parameter
* Supports substitutions in @Headers like in @Body, that is with parts of the value

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please take the below text and place it into the PR description and link to that. Entries are mostly one sentence which allows folks uninterested to skip easier. Ex "supports substitutions in @Headers like in @Body. See #326

Note I escaped the @

@codefromthecrypt

codefromthecrypt commented Feb 13, 2016 via email

Copy link
Copy Markdown

@cloudbees-pull-request-builder

Copy link
Copy Markdown

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

@ahus1

ahus1 commented Feb 13, 2016

Copy link
Copy Markdown
Contributor Author

Changelog updated. Content moved to PR description (at the very top of this discussion to make it easier to find)

codefromthecrypt pushed a commit that referenced this pull request Feb 15, 2016
make replacements header values work like in the body
@codefromthecrypt
codefromthecrypt merged commit e93b6a0 into OpenFeign:master Feb 15, 2016
@codefromthecrypt codefromthecrypt modified the milestones: 8.16, 8.15, 8.15.0 Mar 5, 2016
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
make replacements header values work like in the body
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.

3 participants