Skip to content

Commit

Permalink
[SRE -23218] Brotli encoding support in proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-mcgoldrick authored Jun 7, 2022
1 parent 7122e79 commit 06a675a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
6 changes: 6 additions & 0 deletions proxy-parent/owasp-proxy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@
<artifactId>validation-api</artifactId>
</dependency>

<dependency>
<groupId>org.brotli</groupId>
<artifactId>dec</artifactId>
<version>0.1.2</version>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ public class HttpConstants {

public final static String DEFLATE = "deflate";

public final static String BROTLI = "br";

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

package org.owasp.proxy.http;

import static org.owasp.proxy.http.HttpConstants.BROTLI;
import static org.owasp.proxy.http.HttpConstants.CHUNKED;
import static org.owasp.proxy.http.HttpConstants.CONTENT_ENCODING;
import static org.owasp.proxy.http.HttpConstants.CONTENT_LENGTH;
Expand All @@ -35,6 +36,7 @@
import java.io.InputStream;
import java.io.OutputStream;

import org.brotli.dec.BrotliInputStream;
import org.owasp.proxy.io.ChunkedInputStream;
import org.owasp.proxy.io.ChunkingInputStream;
import org.owasp.proxy.io.CopyInputStream;
Expand Down Expand Up @@ -111,6 +113,10 @@ public static InputStream decode(String codings, InputStream content)
content = new DeflaterInputStream(content);
} else if (GZIP.equalsIgnoreCase(algo)) {
content = new GunzipInputStream(content);
} else if (BROTLI.equalsIgnoreCase(algo)) {
try {
content = new BrotliInputStream(content);
} catch (IOException e) {}
} else if (IDENTITY.equalsIgnoreCase(algo)) {
// nothing to do
} else
Expand Down Expand Up @@ -179,6 +185,10 @@ public static InputStream encode(String codings, InputStream content)
content = new ChunkingInputStream(content);
} else if (GZIP.equalsIgnoreCase(algo)) {
content = new GzipInputStream(content);
} else if (BROTLI.equalsIgnoreCase(algo)) {
try {
content = new BrotliInputStream(content);
} catch (IOException e) {}
} else if (IDENTITY.equalsIgnoreCase(algo)) {
// nothing to do
} else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void checkClientTrusted(X509Certificate[] certs, String authType) {
trusted.put(certs[0], certs);
} catch (CertificateException ce) {
untrusted.put(certs[0], certs);
System.err.printf("Untrusted client certificate for %s", dn);
System.err.printf("Untrusted client certificate for %s\n", dn);
}
}

Expand All @@ -143,7 +143,7 @@ public void checkServerTrusted(X509Certificate[] certs, String authType) {
trusted.put(certs[0], certs);
} catch (CertificateException ce) {
untrusted.put(certs[0], certs);
System.err.printf("Untrusted server certificate for %s", dn);
System.err.printf("Untrusted server certificate for %s\n", dn);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public synchronized void setResponseForCurrentTransaction(Transaction transactio
if (proxyConfiguration.isFollowRedirects() && statusCode == 302) { // redirect
String location = hp.getRedirectLocation();

System.out.println("Pushing redirect location " + location + " with transaction firstline "
System.out.println("Pushing redirect location " + location + "\n\twith transaction firstline "
+ transaction.getRequest().getFirstLine());

if (!transaction.getRequest().getHeaders().contains(REDIRECT_MARKER)) {
Expand Down

0 comments on commit 06a675a

Please sign in to comment.