Skip to content
Snippets Groups Projects
Commit 35aca96d authored by Clayton, Brandon Scott's avatar Clayton, Brandon Scott
Browse files

add context path cookie

parent 14236641
No related branches found
No related tags found
1 merge request!522Updates
package gov.usgs.earthquake.nshmp.www;
import java.time.Duration;
import org.reactivestreams.Publisher;
import io.micronaut.context.annotation.Requires;
import io.micronaut.context.annotation.Value;
import io.micronaut.core.async.publisher.Publishers;
import io.micronaut.http.HttpMethod;
import io.micronaut.http.HttpRequest;
import io.micronaut.http.MutableHttpResponse;
import io.micronaut.http.annotation.Filter;
import io.micronaut.http.cookie.Cookie;
import io.micronaut.http.filter.HttpServerFilter;
import io.micronaut.http.filter.ServerFilterChain;
/**
* Add context path as a cookie for Swagger to use.
*
* @author U.S. Geological Survey
*/
@Requires(property = "micronaut.server.context-path")
@Filter(methods = { HttpMethod.GET, HttpMethod.HEAD },
patterns = { "/**" })
public class ContextPathCookie implements HttpServerFilter {
private final Cookie contextPathCookie;
ContextPathCookie(@Value("${micronaut.server.context-path}") String contextPath) {
this.contextPathCookie = Cookie.of("contextPath", contextPath).maxAge(Duration.ofMinutes(2L));
}
@Override
public Publisher<MutableHttpResponse<?>> doFilter(HttpRequest<?> request,
ServerFilterChain chain) {
return Publishers.map(chain.proceed(request), response -> response.cookie(contextPathCookie));
}
}
...@@ -19,9 +19,9 @@ import gov.usgs.earthquake.nshmp.www.meta.Status; ...@@ -19,9 +19,9 @@ import gov.usgs.earthquake.nshmp.www.meta.Status;
import io.micronaut.http.HttpResponse; import io.micronaut.http.HttpResponse;
class ServicesUtil { public class ServicesUtil {
static HttpResponse<String> handleError( public static HttpResponse<String> handleError(
Throwable e, Throwable e,
String name, String name,
String url) { String url) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment