forked from ratpack/ratpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Streamline the response handling to reduce the amount of garbage crea…
…ted per request.
- Loading branch information
Showing
39 changed files
with
379 additions
and
529 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 0 additions & 124 deletions
124
ratpack-core/src/main/java/ratpack/file/internal/DefaultFileHttpTransmitter.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 0 additions & 28 deletions
28
ratpack-core/src/main/java/ratpack/file/internal/FileHttpTransmitter.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
ratpack-core/src/main/java/ratpack/file/internal/ShouldCompressPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright 2014 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package ratpack.file.internal; | ||
|
||
import com.google.common.base.Predicate; | ||
import com.google.common.cache.CacheBuilder; | ||
import com.google.common.cache.CacheLoader; | ||
import com.google.common.cache.LoadingCache; | ||
import com.google.common.collect.ImmutableSet; | ||
import com.google.common.util.concurrent.UncheckedExecutionException; | ||
import ratpack.func.Pair; | ||
|
||
import java.util.concurrent.ExecutionException; | ||
|
||
import static ratpack.util.ExceptionUtils.toException; | ||
import static ratpack.util.ExceptionUtils.uncheck; | ||
|
||
public class ShouldCompressPredicate implements Predicate<Pair<Long, String>> { | ||
|
||
private final long compressionMinSize; | ||
private final ImmutableSet<String> compressionMimeTypeWhiteList; | ||
private final ImmutableSet<String> compressionMimeTypeBlackList; | ||
|
||
private final LoadingCache<String, Boolean> cache = CacheBuilder.newBuilder().build(new CacheLoader<String, Boolean>() { | ||
@Override | ||
public Boolean load(@SuppressWarnings("NullableProblems") String key) throws Exception { | ||
for (String s : compressionMimeTypeWhiteList) { | ||
if (key.startsWith(s)) { | ||
return true; | ||
} | ||
} | ||
for (String s : compressionMimeTypeBlackList) { | ||
if (key.startsWith(s)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
}); | ||
|
||
public ShouldCompressPredicate(long compressionMinSize, ImmutableSet<String> compressionMimeTypeWhiteList, ImmutableSet<String> compressionMimeTypeBlackList) { | ||
this.compressionMinSize = compressionMinSize; | ||
this.compressionMimeTypeWhiteList = compressionMimeTypeWhiteList; | ||
this.compressionMimeTypeBlackList = compressionMimeTypeBlackList; | ||
} | ||
|
||
@Override | ||
public boolean apply(Pair<Long, String> fileDetails) { | ||
if (fileDetails.left < compressionMinSize) { | ||
return false; | ||
} | ||
|
||
try { | ||
return cache.get(fileDetails.right); | ||
} catch (ExecutionException | UncheckedExecutionException e) { | ||
throw uncheck(toException(e.getCause())); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.