Skip to content

Commit

Permalink
[#11] remove http request consumer(duplicate with httpHandler)
Browse files Browse the repository at this point in the history
  • Loading branch information
fzdwx committed May 16, 2022
1 parent 44a7dc8 commit 43e98fb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 25 deletions.
10 changes: 5 additions & 5 deletions sky-infrastructure/src/main/java/http/HttpServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import core.Server;
import core.Transport;
import http.ext.HttpExceptionHandler;
import http.ext.HttpRequestConsumer;
import http.ext.HttpHandler;
import io.github.fzdwx.lambada.Console;
import io.github.fzdwx.lambada.fun.Hooks;
import io.netty.channel.ChannelFuture;
Expand Down Expand Up @@ -38,7 +38,7 @@ public class HttpServer implements Transport<HttpServer> {
private final Server server;
private boolean sslFlag;
private HttpDataFactory httpDataFactory;
private HttpRequestConsumer consumer;
private HttpHandler httpHandler;
private HttpExceptionHandler exceptionHandler;
private Hooks<ChannelFuture> afterListenHooks;

Expand Down Expand Up @@ -90,7 +90,7 @@ public HttpServer listen(final InetSocketAddress address) {
.addLast(new HttpObjectAggregator(1024 * 1024))
.addLast(new ChunkedWriteHandler())
.addLast(new HttpServerExpectContinueHandler())
.addLast(new HttpServerHandler(consumer, exceptionHandler, sslFlag, httpDataFactory, serializer()));
.addLast(new HttpServerHandler(httpHandler, exceptionHandler, sslFlag, httpDataFactory, serializer()));
}).listen(address);

return this;
Expand Down Expand Up @@ -241,8 +241,8 @@ public HttpServer withHttpDataFactory(final HttpDataFactory factory) {
/**
* handler request and return response.
*/
public HttpServer handle(final HttpRequestConsumer consumer) {
this.consumer = consumer;
public HttpServer handle(final HttpHandler httpHandler) {
this.httpHandler = httpHandler;
return this;
}

Expand Down
10 changes: 5 additions & 5 deletions sky-infrastructure/src/main/java/http/HttpServerHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import core.Netty;
import http.ext.HttpExceptionHandler;
import http.ext.HttpRequestConsumer;
import http.ext.HttpHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.codec.http.FullHttpRequest;
Expand All @@ -15,15 +15,15 @@
@Slf4j
public class HttpServerHandler extends ChannelInboundHandlerAdapter {

private final HttpRequestConsumer consumer;
private final HttpHandler httpHandler;
private final boolean ssl;
private final HttpDataFactory httpDataFactory;
private final HttpExceptionHandler exceptionHandler;
private final JsonSerializer serializer;

public HttpServerHandler(final HttpRequestConsumer consumer, final HttpExceptionHandler exceptionHandler, final Boolean ssl,
public HttpServerHandler(final HttpHandler httpHandler, final HttpExceptionHandler exceptionHandler, final Boolean ssl,
final HttpDataFactory httpDataFactory, final JsonSerializer serializer) {
this.consumer = consumer;
this.httpHandler = httpHandler;
this.exceptionHandler = HttpExceptionHandler.defaultExceptionHandler(exceptionHandler);
this.ssl = ssl;
this.httpDataFactory = httpDataFactory == null ? new DefaultHttpDataFactory(DefaultHttpDataFactory.MINSIZE) : httpDataFactory;
Expand Down Expand Up @@ -67,7 +67,7 @@ public void handleRequest(final ChannelHandlerContext ctx, final FullHttpRequest
final var response = HttpServerResponse.create(ctx.channel(), httpRequest);

try {
consumer.consume(httpRequest, response);
httpHandler.handle(httpRequest, response);
} catch (Exception e) {
exceptionHandler.handler(httpRequest, response, e);
} finally {
Expand Down
15 changes: 0 additions & 15 deletions sky-infrastructure/src/main/java/http/ext/HttpRequestConsumer.java

This file was deleted.

0 comments on commit 43e98fb

Please sign in to comment.