Browse Source

Headers substitutions were not being expanded by the value name, instead it was using the header name..

pull/161/head
jdamick 10 years ago
parent
commit
74e23ef808
  1. 2
      core/src/main/java/feign/RequestTemplate.java
  2. 8
      core/src/test/java/feign/DefaultContractTest.java
  3. 11
      core/src/test/java/feign/RequestTemplateTest.java

2
core/src/main/java/feign/RequestTemplate.java

@ -205,7 +205,7 @@ public final class RequestTemplate implements Serializable { @@ -205,7 +205,7 @@ public final class RequestTemplate implements Serializable {
for (String value : valuesOrEmpty(headers, field)) {
String resolved;
if (value.indexOf('{') == 0) {
resolved = String.valueOf(unencoded.get(field));
resolved = expand(value, unencoded);
} else {
resolved = value;
}

8
core/src/test/java/feign/DefaultContractTest.java

@ -245,10 +245,10 @@ public class DefaultContractTest { @@ -245,10 +245,10 @@ public class DefaultContractTest {
HeaderParams.class.getDeclaredMethod("logout", String.class));
assertThat(md.template())
.hasHeaders(entry("Auth-Token", asList("{Auth-Token}", "Foo")));
.hasHeaders(entry("Auth-Token", asList("{authToken}", "Foo")));
assertThat(md.indexToName())
.containsExactly(entry(0, asList("Auth-Token")));
.containsExactly(entry(0, asList("authToken")));
}
@Test
@ -343,8 +343,8 @@ public class DefaultContractTest { @@ -343,8 +343,8 @@ public class DefaultContractTest {
interface HeaderParams {
@RequestLine("POST /")
@Headers({"Auth-Token: {Auth-Token}", "Auth-Token: Foo"})
void logout(@Param("Auth-Token") String token);
@Headers({"Auth-Token: {authToken}", "Auth-Token: Foo"})
void logout(@Param("authToken") String token);
}
interface CustomExpander {

11
core/src/test/java/feign/RequestTemplateTest.java

@ -126,6 +126,17 @@ public class RequestTemplateTest { @@ -126,6 +126,17 @@ public class RequestTemplateTest {
);
}
@Test
public void resolveTemplateWithHeaderSubstitutions() {
RequestTemplate template = new RequestTemplate().method("GET")
.header("Auth-Token", "{authToken}");
template.resolve(mapOf("authToken", "1234"));
assertThat(template)
.hasHeaders(entry("Auth-Token", asList("1234")));
}
@Test
public void resolveTemplateWithMixedRequestLineParams() throws Exception {
RequestTemplate template = new RequestTemplate().method("GET")//

Loading…
Cancel
Save