Skip to content

Commit c86206f

Browse files
committed
Working
1 parent 00943bf commit c86206f

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/main/java/io/fusionauth/http/server/Configurable.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ default T withChunkedBufferSize(int chunkedBufferSize) {
6161
/**
6262
* Sets the default compression behavior for the HTTP response. This behavior can be optionally set per response. See
6363
* {@link HTTPResponse#setCompress(boolean)}. Defaults to true.
64+
* <p>
65+
* Set this configuration to <code>true</code> if you want to compress the response when the Accept-Encoding header is present. Set this
66+
* configuration to <code>false</code> if you want to require the request handler to use {@link HTTPResponse#setCompress(boolean)} in
67+
* order to compress the response.
68+
* <p>
69+
* Regardless of this configuration, you always have the option to use {@link HTTPResponse#setCompress(boolean)} on a per-response basis
70+
* as an override.
71+
* <p>
72+
* When the request does not contain an Accept-Encoding the response will not be compressed regardless of this configuration.
6473
*
6574
* @param compressByDefault true if you want to compress by default, or false to not compress by default.
6675
* @return This.

src/main/java/io/fusionauth/http/server/io/HTTPInputStream.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,17 @@ public int read(byte[] b, int off, int len) throws IOException {
135135
return 0;
136136
}
137137

138+
// TODO : Re: Compression - fixedLength and Content-Length needs to account for the Content-Length referring to the compressed body.
139+
140+
// Preamble, this could push back compressed bytes.
141+
// Pushback > Throughput > Socket
142+
//
143+
// HTTPInputStream (this) -> Decompress > Pushback > Throughput > Socket
144+
// HTTPInputStream (this) -> Decompress > Chunked > Pushback > Throughput > Socket
145+
//
146+
// Pushback doesn't care if the bytes are compressed or not, it is up to the caller?
147+
//
148+
138149
// If this is a fixed length request, and we have less than or equal to 0 bytes remaining, return -1
139150
boolean fixedLength = !request.isChunked();
140151
if (fixedLength && bytesRemaining <= 0) {
@@ -147,7 +158,11 @@ public int read(byte[] b, int off, int len) throws IOException {
147158

148159
// When we have a fixed length request, read beyond the remainingBytes if possible.
149160
// - If we have read past the end of the current request, push those bytes back onto the InputStream.
150-
int read = delegate.read(b, off, len);
161+
// TODO : Can I optionally never override here? If I am fixed length, I could change len -> maxLen., and then never pushback.
162+
// Would this help with compression?
163+
// int maxLen = (int) Math.min(len, bytesRemaining);
164+
int maxLen = len;
165+
int read = delegate.read(b, off, maxLen);
151166
if (fixedLength && read > 0) {
152167
int extraBytes = (int) (read - bytesRemaining);
153168
if (extraBytes > 0) {

0 commit comments

Comments
 (0)