Skip to content

Commit 414ac48

Browse files
committed
Netty: clean/remove dead code
1 parent a0e2f8b commit 414ac48

File tree

2 files changed

+14
-37
lines changed

2 files changed

+14
-37
lines changed

modules/jooby-netty/src/main/java/io/jooby/internal/netty/NettyContext.java

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@
106106
import io.netty.handler.stream.ChunkedStream;
107107
import io.netty.handler.stream.ChunkedWriteHandler;
108108
import io.netty.handler.timeout.IdleStateHandler;
109-
import io.netty.util.ReferenceCounted;
110109

111110
public class NettyContext implements DefaultContext, ChannelFutureListener {
112111

@@ -268,7 +267,7 @@ public QueryString query() {
268267
public Formdata form() {
269268
if (formdata == null) {
270269
formdata = Formdata.create(this);
271-
decodeForm(req, formdata);
270+
decodeForm(formdata);
272271
}
273272
return formdata;
274273
}
@@ -832,8 +831,7 @@ private boolean pendingTasks() {
832831
return (getSession() != null)
833832
|| (listeners != null)
834833
|| (files != null && files.size() > 0)
835-
|| (decoder != null)
836-
|| shouldRelease(req);
834+
|| (decoder != null);
837835
}
838836

839837
void destroy(Throwable cause) {
@@ -874,7 +872,6 @@ void destroy(Throwable cause) {
874872
}
875873
decoder = null;
876874
}
877-
release(req);
878875
}
879876

880877
private NettyOutputStream newOutputStream() {
@@ -891,7 +888,7 @@ private FileUpload register(FileUpload upload) {
891888
return upload;
892889
}
893890

894-
private void decodeForm(HttpRequest req, Formdata form) {
891+
private void decodeForm(Formdata form) {
895892
if (decoder == null || decoder instanceof HttpRawPostRequestDecoder) {
896893
// empty/bad form
897894
return;
@@ -900,13 +897,12 @@ private void decodeForm(HttpRequest req, Formdata form) {
900897
while (decoder.hasNext()) {
901898
HttpData next = (HttpData) decoder.next();
902899
if (next.getHttpDataType() == InterfaceHttpData.HttpDataType.FileUpload) {
903-
((Formdata) form)
904-
.put(
905-
next.getName(),
906-
register(
907-
new NettyFileUpload(
908-
router.getTmpdir(),
909-
(io.netty.handler.codec.http.multipart.FileUpload) next)));
900+
form.put(
901+
next.getName(),
902+
register(
903+
new NettyFileUpload(
904+
router.getTmpdir(),
905+
(io.netty.handler.codec.http.multipart.FileUpload) next)));
910906
} else {
911907
form.put(next.getName(), next.getString(UTF_8));
912908
}
@@ -915,24 +911,7 @@ private void decodeForm(HttpRequest req, Formdata form) {
915911
// ignore, silly netty
916912
} catch (Exception x) {
917913
throw SneakyThrows.propagate(x);
918-
} finally {
919-
release(req);
920-
}
921-
}
922-
923-
private static void release(HttpRequest req) {
924-
if (shouldRelease(req)) {
925-
ReferenceCounted ref = (ReferenceCounted) req;
926-
ref.release();
927-
}
928-
}
929-
930-
private static boolean shouldRelease(HttpRequest req) {
931-
if (req instanceof ReferenceCounted) {
932-
ReferenceCounted ref = (ReferenceCounted) req;
933-
return ref.refCnt() > 0;
934914
}
935-
return false;
936915
}
937916

938917
private long responseLength() {

modules/jooby-netty/src/main/java/io/jooby/internal/netty/NettyHandler.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,11 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
188188
}
189189

190190
private void offer(NettyContext context, HttpContent chunk) {
191-
if (context.decoder != null) {
192-
try {
193-
context.decoder.offer(chunk);
194-
} catch (HttpPostRequestDecoder.ErrorDataDecoderException x) {
195-
resetDecoderState(context, true);
196-
context.sendError(x, StatusCode.BAD_REQUEST);
197-
}
191+
try {
192+
context.decoder.offer(chunk);
193+
} catch (HttpPostRequestDecoder.ErrorDataDecoderException x) {
194+
resetDecoderState(context, true);
195+
context.sendError(x, StatusCode.BAD_REQUEST);
198196
}
199197
}
200198

0 commit comments

Comments
 (0)