Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #130 Empty response for NOT_MODIFIED #131

Merged
merged 4 commits into from
Jun 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ private void handleWebSocketFrame(final ChannelHandlerContext ctx, final Object
if (frame instanceof CloseWebSocketFrame) {
ctx.channel().write(frame).addListener(ChannelFutureListener.CLOSE);
} else if (frame instanceof PingWebSocketFrame) {
if (WebSocketPingPongListener.class.isAssignableFrom(webSocketProcessor.getClass())) {
if (body != null && WebSocketPingPongListener.class.isAssignableFrom(webSocketProcessor.getClass())) {
WebSocketPingPongListener.class.cast(webSocketProcessor).onPing(attachment, body, 0, body.length);
} else {
ctx.channel().writeAndFlush(new PongWebSocketFrame(binaryData));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
import java.util.regex.Pattern;

import static io.netty.handler.codec.http.HttpHeaders.Names.CONTENT_TYPE;
import static io.netty.handler.codec.http.HttpHeaders.Names.IF_MODIFIED_SINCE;
import static io.netty.handler.codec.http.HttpHeaders.Names.IF_MODIFIED_SINCE;
import static io.netty.handler.codec.http.HttpHeaders.Names.LOCATION;
import static io.netty.handler.codec.http.HttpMethod.GET;
import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST;
Expand Down Expand Up @@ -146,7 +146,7 @@ public class HttpStaticFileServerHandler extends SimpleChannelInboundHandler<Ful
public final static String STATIC_MAPPING = SimpleChannelInboundHandler.class.getName() + ".staticMapping";
public final static String SERVICED = SimpleChannelInboundHandler.class.getName() + ".serviced";
private final List<String> paths;
private String defaultContentType = "text/html";
private static final String defaultContentType = "text/html";

public HttpStaticFileServerHandler(List<String> paths) {
this.paths = paths;
Expand Down Expand Up @@ -205,6 +205,8 @@ public void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) thr
}
request.headers().add(SERVICED, "true");

ctx.pipeline().addBefore(BridgeRuntime.class.getName(), "encoder", new HttpResponseEncoder());

// Cache Validation
String ifModifiedSince = request.headers().get(IF_MODIFIED_SINCE);
if (ifModifiedSince != null && !ifModifiedSince.isEmpty()) {
Expand All @@ -224,7 +226,7 @@ public void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) thr

long fileLength = raf.length();

ctx.pipeline().addBefore(BridgeRuntime.class.getName(), "encoder", new HttpResponseEncoder());

HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
HttpHeaders.setContentLength(response, fileLength);
contentType(request, response, file);
Expand Down Expand Up @@ -410,7 +412,7 @@ private static void setContentTypeHeader(HttpResponse response, File file) {
response.headers().set(HttpHeaderNames.CONTENT_TYPE, mimeTypesMap.getContentType(file.getPath()));
}

protected void contentType(FullHttpRequest request, HttpResponse response, File resource) {
private static void contentType(FullHttpRequest request, HttpResponse response, File resource) {
String substr;
String uri = request.getUri();
int dot = uri.lastIndexOf(".");
Expand All @@ -425,7 +427,7 @@ protected void contentType(FullHttpRequest request, HttpResponse response, File
String ext = substr.substring(dot + 1);
int queryString = ext.indexOf("?");
if (queryString > 0) {
ext.substring(0, queryString);
ext = ext.substring(0, queryString);
}
String contentType = MimeType.get(ext, defaultContentType);
response.headers().add(HttpHeaders.Names.CONTENT_TYPE, contentType);
Expand Down