summaryrefslogtreecommitdiffstats
path: root/common/src/main/java/org/onap/so/client/AddCacheHeaders.java
blob: 1a41be12337919b923e80efeed6239447b3032e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package org.onap.so.client;

import java.io.IOException;
import java.util.Collections;
import javax.annotation.Priority;
import javax.ws.rs.client.ClientRequestContext;
import javax.ws.rs.client.ClientResponseContext;
import javax.ws.rs.client.ClientResponseFilter;
import javax.ws.rs.ext.Provider;

@Provider
@Priority(1)
public class AddCacheHeaders implements ClientResponseFilter {

    private final CacheProperties props;

    public AddCacheHeaders(CacheProperties props) {
        this.props = props;
    }

    public void filter(ClientRequestContext request, ClientResponseContext response) throws IOException {
        if (request.getMethod().equalsIgnoreCase("GET")) {
            response.getHeaders().putIfAbsent("Cache-Control",
                    Collections.singletonList("public, max-age=" + (props.getMaxAge() / 1000)));
        }

    }
}