Skip to content

Commit d6b0c37

Browse files
committed
Minor cleanup for #735 + couple more of tests
1 parent 9cdc7a3 commit d6b0c37

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed
Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,51 @@
11
package org.jooby.issues;
22

3+
import java.nio.charset.StandardCharsets;
4+
import java.nio.file.Files;
5+
import java.util.concurrent.Executors;
6+
37
import org.jooby.test.ServerFeature;
48
import org.junit.Test;
59

6-
import java.util.concurrent.Executors;
7-
810
public class Issue731 extends ServerFeature {
911

1012
{
1113

1214
executor("worker1", Executors.newSingleThreadExecutor());
1315

14-
post("/", deferred("worker1", req -> req.body(String.class)));
16+
get("/731", deferred("worker1", req -> req.body().toOptional().orElse("nobody")));
17+
18+
post("/731", deferred("worker1", req -> req.body(String.class)));
19+
20+
post("/731/files",
21+
deferred("worker1", req -> Files.readAllBytes(req.file("file").file().toPath())));
1522

1623
}
1724

1825
@Test
1926
public void appShouldBeAbleToReadTheRequestBodyWhenDeferred() throws Exception {
2027
request()
21-
.post("/")
22-
.body("HelloWorld!", "text/plain")
23-
.expect(200)
24-
.expect("HelloWorld!");
28+
.post("/731")
29+
.body("HelloWorld!", "text/plain")
30+
.expect(200)
31+
.expect("HelloWorld!");
32+
}
33+
34+
@Test
35+
public void appShouldBeAbleToReadTheFileWhenDeferred() throws Exception {
36+
request()
37+
.post("/731/files")
38+
.multipart()
39+
.file("file", "HelloWorld!".getBytes(StandardCharsets.UTF_8), "text/plain", "731.txt")
40+
.expect(200)
41+
.expect("HelloWorld!");
42+
}
43+
44+
@Test
45+
public void getShouldNotBeAffected() throws Exception {
46+
request()
47+
.get("/731")
48+
.expect(200)
49+
.expect("nobody");
2550
}
2651
}

jooby-netty/src/main/java/org/jooby/internal/netty/NettyRequest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,13 +244,13 @@ public void startAsync(final Executor executor, final Runnable runnable) {
244244
channel.attr(NEED_FLUSH).set(false);
245245
channel.attr(ASYNC).set(true);
246246

247-
ReferenceCounted referenceCounted = ((ByteBufHolder) req).content();
248-
referenceCounted.retain();
247+
ReferenceCounted body = ((ByteBufHolder) req).content();
248+
body.retain();
249249
executor.execute(() -> {
250250
try {
251251
runnable.run();
252252
} finally {
253-
referenceCounted.release();
253+
body.release();
254254
}
255255
});
256256
}

0 commit comments

Comments
 (0)