forked from docker-java/docker-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectiveLoggingFilter.java
More file actions
43 lines (34 loc) · 1.26 KB
/
Copy pathSelectiveLoggingFilter.java
File metadata and controls
43 lines (34 loc) · 1.26 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.github.dockerjava.core;
import java.io.IOException;
import java.util.Set;
import java.util.logging.Logger;
import javax.ws.rs.client.ClientRequestContext;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import com.google.common.collect.ImmutableSet;
import org.glassfish.jersey.filter.LoggingFilter;
/**
* A version of the logging filter that will avoid trying to log entities which can cause
* issues with the console.
*
* @author sfitts
*
*/
public class SelectiveLoggingFilter extends LoggingFilter {
private static final Set<String> SKIPPED_CONTENT = ImmutableSet.<String>builder()
.add(MediaType.APPLICATION_OCTET_STREAM)
.add("application/tar")
.build();
public SelectiveLoggingFilter(Logger logger, boolean b) {
super(logger, b);
}
@Override
public void filter(ClientRequestContext context) throws IOException {
// Unless the content type is in the list of those we want to ellide, then just have
// our super-class handle things.
Object contentType = context.getHeaders().getFirst(HttpHeaders.CONTENT_TYPE);
if (contentType == null || !SKIPPED_CONTENT.contains(contentType.toString())) {
super.filter(context);
}
}
}