Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding no cache header on failure response #520

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nva.commons.apigateway;

import static com.google.common.net.HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN;
import static com.google.common.net.HttpHeaders.CACHE_CONTROL;
import static com.google.common.net.HttpHeaders.CONTENT_TYPE;
import static com.google.common.net.HttpHeaders.ORIGIN;
import static com.google.common.net.HttpHeaders.STRICT_TRANSPORT_SECURITY;
Expand Down Expand Up @@ -301,6 +302,7 @@ private Map<String, String> getFailureHeaders() {
headers.put(X_CONTENT_TYPE_OPTIONS, "nosniff");
headers.put(STRICT_TRANSPORT_SECURITY, "max-age=63072000; includeSubDomains; preload");
headers.put(VARY, "Origin, Accept");
headers.put(CACHE_CONTROL, "no-cache");
return headers;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package nva.commons.apigateway;

import static com.google.common.net.HttpHeaders.CACHE_CONTROL;
import static com.google.common.net.HttpHeaders.CONTENT_TYPE;
import static com.google.common.net.HttpHeaders.STRICT_TRANSPORT_SECURITY;
import static com.google.common.net.HttpHeaders.VARY;
Expand Down Expand Up @@ -329,6 +330,17 @@ public void getFailureStatusCodeReturnsByDefaultTheStatusCodeOfTheApiGatewayExce
is(equalTo(TestException.ERROR_STATUS_CODE)));
}

@Test
public void shouldReturnFailureHeadersWhenHandlerThrowsException() throws IOException {
var handler = handlerThatThrowsExceptions();

var response = getProblemResponse(anyRequest(), handler);
var headers = response.getHeaders();

assertThat(headers.get(CONTENT_TYPE), is(equalTo(APPLICATION_PROBLEM_JSON.toString())));
assertThat(headers.get(CACHE_CONTROL), is(equalTo("no-cache")));
}

@Test
public void handlerLogsRequestIdForEveryRequest() throws IOException {
var appender = LogUtils.getTestingAppenderForRootLogger();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group 'com.github.bibsysdev'
version = '1.40.20'
version = '1.40.21'

java {
sourceCompatibility = JavaVersion.VERSION_17
Expand Down
Loading