Skip to content

Commit eef3057

Browse files
author
Alex Danilenko
committed
small fixes
1 parent 2dc7830 commit eef3057

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

core/src/main/java/spotty/common/http/ContentEncoding.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@
1515
*/
1616
package spotty.common.http;
1717

18+
import spotty.common.exception.SpottyException;
19+
1820
import java.util.HashMap;
1921
import java.util.Map;
2022

23+
import static java.util.Arrays.asList;
24+
2125
public enum ContentEncoding {
2226
GZIP, DEFLATE;
2327

@@ -31,6 +35,11 @@ public enum ContentEncoding {
3135
}
3236

3337
public static ContentEncoding of(String name) {
34-
return MAPPING.get(name);
38+
final ContentEncoding contentEncoding = MAPPING.get(name);
39+
if (contentEncoding == null) {
40+
throw new SpottyException("Spotty supports " + asList(ContentEncoding.values()) + " compression");
41+
}
42+
43+
return contentEncoding;
3544
}
3645
}

core/src/main/java/spotty/server/handler/request/DefaultRequestHandler.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package spotty.server.handler.request;
1717

18-
import spotty.common.exception.SpottyException;
1918
import spotty.common.filter.Filter;
2019
import spotty.common.http.ContentEncoding;
2120
import spotty.common.request.SpottyDefaultRequest;
@@ -28,7 +27,6 @@
2827

2928
import java.util.Collection;
3029

31-
import static java.util.Arrays.asList;
3230
import static spotty.common.http.HttpHeaders.ACCEPT;
3331
import static spotty.common.http.HttpHeaders.CONTENT_ENCODING;
3432
import static spotty.common.validation.Validation.notNull;
@@ -79,9 +77,6 @@ public void handle(SpottyDefaultRequest request, SpottyResponse response) throws
7977

8078
if (response.headers().has(CONTENT_ENCODING)) {
8179
final ContentEncoding contentEncoding = ContentEncoding.of(response.headers().get(CONTENT_ENCODING));
82-
if (contentEncoding == null) {
83-
throw new SpottyException("Spotty supports " + asList(ContentEncoding.values()) + " compression");
84-
}
8580

8681
body = compressor.compress(contentEncoding, body);
8782
}

core/src/main/java/spotty/server/worker/ReactorWorker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ ThreadPoolExecutor reactorPool() {
6969
*/
7070
private static class RejectedHandler implements RejectedExecutionHandler {
7171

72-
private final ExecutorService rejectedHandlerExecutor = newSingleThreadExecutor();
72+
private final ExecutorService rejectedHandlerExecutor = newSingleThreadExecutor(threadPool("spotty-reactor-rejected-handler"));
7373

7474
@Override
7575
public void rejectedExecution(Runnable task, ThreadPoolExecutor executor) {

core/src/test/groovy/spotty/server/connection/ConnectionTest.groovy

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import spotty.common.response.SpottyResponse
1010
import spotty.common.stream.output.SpottyByteArrayOutputStream
1111
import spotty.server.connection.socket.SocketFactory
1212
import spotty.server.handler.EchoRequestHandler
13+
import spotty.server.handler.request.RequestHandler
1314
import spotty.server.registry.exception.ExceptionHandlerRegistry
1415
import spotty.server.worker.ReactorWorker
1516
import stub.SocketChannelStub
@@ -61,13 +62,14 @@ class ConnectionTest extends Specification implements WebRequestTestData {
6162

6263
def "should read request correctly"() {
6364
given:
65+
final RequestHandler delayHandler = (req, res) -> Thread.sleep(1000)
6466
var expectedRequest = aSpottyRequest()
6567
var socket = new SocketChannelStub(fullRequest.length())
6668
socket.configureBlocking(false)
6769
socket.write(fullRequest)
6870
socket.flip()
6971

70-
var connection = new Connection(socketFactory.createSocket(socket), new EchoRequestHandler(), reactorWorker, exceptionService, maxBodyLimit)
72+
var connection = new Connection(socketFactory.createSocket(socket), delayHandler, reactorWorker, exceptionService, maxBodyLimit)
7173
connection.markReadyToRead()
7274

7375
when:

0 commit comments

Comments
 (0)