Skip to content

Commit 92826cf

Browse files
committed
POST endpoint with Pac4j module kills Jooby server fix jooby-project#1548
- issue affect netty server (undertow and jetty were OK)
1 parent 0f4471c commit 92826cf

File tree

6 files changed

+47
-1
lines changed

6 files changed

+47
-1
lines changed

jooby/src/main/java/io/jooby/Context.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,13 @@ public interface Context extends Registry {
600600
*/
601601
@Nonnull Multipart multipart();
602602

603+
/**
604+
* Whether request content type is set to <code>application/x-www-form-urlencoded</code> or
605+
* <code>multipart/*</code>
606+
* @return
607+
*/
608+
boolean isForm();
609+
603610
/**
604611
* Get a multipart field that matches the given name.
605612
*

jooby/src/main/java/io/jooby/DefaultContext.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,17 @@ public interface DefaultContext extends Context {
9393
.create(this, new Cookie(getRouter().getFlashCookie()).setHttpOnly(true)));
9494
}
9595

96+
@Override default boolean isForm() {
97+
String contentType = header("Content-Type").value("");
98+
if (contentType.equalsIgnoreCase(MediaType.FORM_URLENCODED)) {
99+
return true;
100+
}
101+
if (contentType.toLowerCase().startsWith(MediaType.MULTIPART_FORMDATA)) {
102+
return true;
103+
}
104+
return false;
105+
}
106+
96107
/**
97108
* Get a flash attribute.
98109
*

jooby/src/main/java/io/jooby/ForwardingContext.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ public ForwardingContext(@Nonnull Context context) {
201201
return ctx.getRequestType(defaults);
202202
}
203203

204+
@Override public boolean isForm() {
205+
return ctx.isForm();
206+
}
207+
204208
@Override public long getRequestLength() {
205209
return ctx.getRequestLength();
206210
}

modules/jooby-jetty/src/main/java/io/jooby/internal/jetty/JettyContext.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
import java.util.LinkedHashMap;
6868
import java.util.List;
6969
import java.util.Map;
70+
import java.util.Optional;
7071
import java.util.concurrent.Executor;
7172

7273
import static org.eclipse.jetty.http.HttpHeader.CONTENT_TYPE;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ private FileUpload register(FileUpload upload) {
700700
}
701701

702702
private void decodeForm(HttpRequest req, Formdata form) {
703-
if (decoder == null) {
703+
if (decoder == null || decoder instanceof HttpRawPostRequestDecoder) {
704704
// empty/bad form
705705
return;
706706
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package io.jooby;
2+
3+
import io.jooby.junit.ServerTest;
4+
import io.jooby.junit.ServerTestRunner;
5+
import okhttp3.MediaType;
6+
7+
import static okhttp3.RequestBody.create;
8+
import static org.junit.jupiter.api.Assertions.assertEquals;
9+
10+
public class Issue1548 {
11+
12+
@ServerTest
13+
public void issue1548(ServerTestRunner runner) {
14+
runner.define(app -> {
15+
app.post("/1548", ctx -> ctx.multipart().toString());
16+
}).ready(client -> {
17+
client
18+
.post("/1548", create("{\"foo\": \"bar\"}", MediaType.parse("application/json")), rsp -> {
19+
assertEquals("{}", rsp.body().string());
20+
});
21+
});
22+
}
23+
}

0 commit comments

Comments
 (0)