Skip to content

Commit

Permalink
refactor(GraylogHttpOutput): remove the ability to gzip sent payloads
Browse files Browse the repository at this point in the history
  • Loading branch information
squioc committed Dec 14, 2021
1 parent 3759c6b commit 3d5d2e3
Showing 1 changed file with 0 additions and 50 deletions.
50 changes: 0 additions & 50 deletions src/main/java/com/plugin/HttpOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,53 +42,10 @@ public class HttpOutput implements MessageOutput {
private String intake_key;
private static final String CK_OUTPUT_API = "output_api";
private static final String CK_INTAKE_KEY = "intake_key";
private static final String CK_GZIP_REQUEST = "gzip_request";
private static final String CK_RAISE_EXCEPTION = "raise_exception";
private static final Logger LOG = LoggerFactory.getLogger(HttpOutput.class);
private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");

/**
* This interceptor compresses the HTTP request body. Many webservers can't handle this!
* <p>
* taken from https://square.github.io/okhttp/interceptors/
*/
final class GzipRequestInterceptor implements Interceptor {
@Override
public Response intercept(Interceptor.Chain chain) throws IOException {
Request originalRequest = chain.request();
if (originalRequest.body() == null || originalRequest.header("Content-Encoding") != null) {
return chain.proceed(originalRequest);
}

Request compressedRequest = originalRequest.newBuilder()
.header("Content-Encoding", "gzip")
.method(originalRequest.method(), gzip(originalRequest.body()))
.build();
return chain.proceed(compressedRequest);
}

private RequestBody gzip(final RequestBody body) {
return new RequestBody() {
@Override
public MediaType contentType() {
return body.contentType();
}

@Override
public long contentLength() {
return -1; // We don't know the compressed length in advance!
}

@Override
public void writeTo(BufferedSink sink) throws IOException {
BufferedSink gzipSink = Okio.buffer(new GzipSink(sink));
body.writeTo(gzipSink);
gzipSink.close();
}
};
}
}

@Inject
public HttpOutput(@Assisted Stream stream, @Assisted Configuration conf) throws HttpOutputException {

Expand All @@ -100,7 +57,6 @@ public HttpOutput(@Assisted Stream stream, @Assisted Configuration conf) throws
LOG.info(" Http Output Plugin has been configured with the following parameters:");
LOG.info(CK_OUTPUT_API + " : " + this.url);
LOG.info(CK_INTAKE_KEY + " : " + this.intake_key);
LOG.info(CK_GZIP_REQUEST + " : " + conf.getBoolean(CK_GZIP_REQUEST));
LOG.info(CK_RAISE_EXCEPTION + " : " + this.raise_exception_on_http_error);

try {
Expand All @@ -115,9 +71,6 @@ public HttpOutput(@Assisted Stream stream, @Assisted Configuration conf) throws
.writeTimeout(10, TimeUnit.SECONDS)
.readTimeout(5, TimeUnit.SECONDS);

if (conf.getBoolean(CK_GZIP_REQUEST)) {
clientBuilder.addInterceptor(new GzipRequestInterceptor());
}
this.httpClient = clientBuilder.build();
}

Expand Down Expand Up @@ -207,9 +160,6 @@ public ConfigurationRequest getRequestedConfiguration() {
new TextField(CK_INTAKE_KEY, "Intake key", "",
"The intake key to identify the events", ConfigurationField.Optional.NOT_OPTIONAL));

configurationRequest.addField(new BooleanField(CK_GZIP_REQUEST, "GZIP request", false,
"Enable GZIP compression for HTTP requests."));

configurationRequest.addField(new BooleanField(CK_RAISE_EXCEPTION, "Raise exception", false,
"Raise an exception on HTTP error"));

Expand Down

0 comments on commit 3d5d2e3

Please sign in to comment.