Skip to content

Commit

Permalink
Do not set Accept header for Contentful API
Browse files Browse the repository at this point in the history
Closes gh-3
  • Loading branch information
sjohnr committed Jan 2, 2024
1 parent 181e9c5 commit ba9fd5a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
3 changes: 1 addition & 2 deletions api/sagan/src/main/java/io/spring/api/SaganApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ public Generation getGeneration(String slug, String name) {
private HttpRequest.Builder requestBuilder(String uri) {
// @formatter:off
HttpRequest.Builder builder = HttpRequest.newBuilder()
.uri(URI.create(this.baseUrl + uri).normalize())
.header("Accept", "application/json");
.uri(URI.create(this.baseUrl + uri).normalize());
// @formatter:on
if (this.username != null && this.accessToken != null) {
var credentials = "%s:%s".formatted(this.username, this.accessToken);
Expand Down
22 changes: 11 additions & 11 deletions api/sagan/src/test/java/io/spring/api/SaganApiTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void getProjectsWhenExistsThenSuccess() throws Exception {
var recordedRequest = this.server.takeRequest();
assertThat(recordedRequest.getMethod()).isEqualTo("GET");
assertThat(recordedRequest.getPath()).isEqualTo("/projects");
assertThat(recordedRequest.getHeader("Accept")).isEqualTo("application/json");
assertThat(recordedRequest.getHeader("Accept")).isNull();
assertThat(recordedRequest.getHeader("Authorization")).isEqualTo("Basic %s".formatted(AUTH_TOKEN));
}

Expand All @@ -92,7 +92,7 @@ public void getProjectWhenUsernameAndAccessTokenAreNullThenSuccess() throws Exce
var recordedRequest = this.server.takeRequest();
assertThat(recordedRequest.getMethod()).isEqualTo("GET");
assertThat(recordedRequest.getPath()).isEqualTo("/projects/spring-security");
assertThat(recordedRequest.getHeader("Accept")).isEqualTo("application/json");
assertThat(recordedRequest.getHeader("Accept")).isNull();
assertThat(recordedRequest.getHeaders().names().contains("Authorization")).isFalse();
}

Expand All @@ -107,7 +107,7 @@ public void getProjectWhenExistsThenSuccess() throws Exception {
var recordedRequest = this.server.takeRequest();
assertThat(recordedRequest.getMethod()).isEqualTo("GET");
assertThat(recordedRequest.getPath()).isEqualTo("/projects/spring-security");
assertThat(recordedRequest.getHeader("Accept")).isEqualTo("application/json");
assertThat(recordedRequest.getHeader("Accept")).isNull();
assertThat(recordedRequest.getHeader("Authorization")).isEqualTo("Basic %s".formatted(AUTH_TOKEN));
}

Expand All @@ -125,7 +125,7 @@ public void getReleasesWhenExistsThenSuccess() throws Exception {
var recordedRequest = this.server.takeRequest();
assertThat(recordedRequest.getMethod()).isEqualTo("GET");
assertThat(recordedRequest.getPath()).isEqualTo("/projects/spring-security/releases");
assertThat(recordedRequest.getHeader("Accept")).isEqualTo("application/json");
assertThat(recordedRequest.getHeader("Accept")).isNull();
assertThat(recordedRequest.getHeader("Authorization")).isEqualTo("Basic %s".formatted(AUTH_TOKEN));
}

Expand All @@ -139,7 +139,7 @@ public void getReleasesWhenEndOfLifeThenEmpty() throws Exception {
var recordedRequest = this.server.takeRequest();
assertThat(recordedRequest.getMethod()).isEqualTo("GET");
assertThat(recordedRequest.getPath()).isEqualTo("/projects/spring-social/releases");
assertThat(recordedRequest.getHeader("Accept")).isEqualTo("application/json");
assertThat(recordedRequest.getHeader("Accept")).isNull();
assertThat(recordedRequest.getHeader("Authorization")).isEqualTo("Basic %s".formatted(AUTH_TOKEN));
}

Expand All @@ -151,7 +151,7 @@ public void createReleaseWhenValidParametersThenSuccess() throws Exception {
var recordedRequest = this.server.takeRequest();
assertThat(recordedRequest.getMethod()).isEqualTo("POST");
assertThat(recordedRequest.getPath()).isEqualTo("/projects/spring-security/releases");
assertThat(recordedRequest.getHeader("Accept")).isEqualTo("application/json");
assertThat(recordedRequest.getHeader("Accept")).isNull();
assertThat(recordedRequest.getHeader("Content-Type")).isEqualTo("application/json");
assertThat(recordedRequest.getHeader("Authorization")).isEqualTo("Basic %s".formatted(AUTH_TOKEN));
assertThat(recordedRequest.getBody().readString(Charset.defaultCharset()))
Expand All @@ -170,7 +170,7 @@ public void getReleaseWhenExistsThenSuccess() throws Exception {
var recordedRequest = this.server.takeRequest();
assertThat(recordedRequest.getMethod()).isEqualTo("GET");
assertThat(recordedRequest.getPath()).isEqualTo("/projects/spring-security/releases/6.1.0");
assertThat(recordedRequest.getHeader("Accept")).isEqualTo("application/json");
assertThat(recordedRequest.getHeader("Accept")).isNull();
assertThat(recordedRequest.getHeader("Authorization")).isEqualTo("Basic %s".formatted(AUTH_TOKEN));
}

Expand All @@ -182,7 +182,7 @@ public void deleteReleaseWhenValidParametersThenSuccess() throws Exception {
var recordedRequest = this.server.takeRequest();
assertThat(recordedRequest.getMethod()).isEqualTo("DELETE");
assertThat(recordedRequest.getPath()).isEqualTo("/projects/spring-security/releases/6.1.0");
assertThat(recordedRequest.getHeader("Accept")).isEqualTo("application/json");
assertThat(recordedRequest.getHeader("Accept")).isNull();
assertThat(recordedRequest.getHeader("Authorization")).isEqualTo("Basic %s".formatted(AUTH_TOKEN));
}

Expand All @@ -207,7 +207,7 @@ public void getGenerationsWhenExistsThenSuccess() throws Exception {
var recordedRequest = this.server.takeRequest();
assertThat(recordedRequest.getMethod()).isEqualTo("GET");
assertThat(recordedRequest.getPath()).isEqualTo("/projects/spring-security/generations");
assertThat(recordedRequest.getHeader("Accept")).isEqualTo("application/json");
assertThat(recordedRequest.getHeader("Accept")).isNull();
assertThat(recordedRequest.getHeader("Authorization")).isEqualTo("Basic %s".formatted(AUTH_TOKEN));
}

Expand All @@ -221,7 +221,7 @@ public void getGenerationsWhenEndOfLifeThenEmpty() throws Exception {
var recordedRequest = this.server.takeRequest();
assertThat(recordedRequest.getMethod()).isEqualTo("GET");
assertThat(recordedRequest.getPath()).isEqualTo("/projects/spring-social/generations");
assertThat(recordedRequest.getHeader("Accept")).isEqualTo("application/json");
assertThat(recordedRequest.getHeader("Accept")).isNull();
assertThat(recordedRequest.getHeader("Authorization")).isEqualTo("Basic %s".formatted(AUTH_TOKEN));
}

Expand All @@ -239,7 +239,7 @@ public void getGenerationWhenExistsThenSuccess() throws Exception {
var recordedRequest = this.server.takeRequest();
assertThat(recordedRequest.getMethod()).isEqualTo("GET");
assertThat(recordedRequest.getPath()).isEqualTo("/projects/spring-security/generations/6.1.x");
assertThat(recordedRequest.getHeader("Accept")).isEqualTo("application/json");
assertThat(recordedRequest.getHeader("Accept")).isNull();
assertThat(recordedRequest.getHeader("Authorization")).isEqualTo("Basic %s".formatted(AUTH_TOKEN));
}

Expand Down

0 comments on commit ba9fd5a

Please sign in to comment.