Skip to content

Commit fbfbc54

Browse files
committed
优化 solon-handle Action 默认为 TEXT_PLAIN_UTF8_VALUE
1 parent 86d6684 commit fbfbc54

File tree

9 files changed

+189
-5
lines changed

9 files changed

+189
-5
lines changed

solon-jakarta-projects/solon-server/solon-server-jetty-jakarta/src/test/java/features/jetty/App.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
@Controller
1313
public class App {
1414
public static void main(String[] args) {
15-
Solon.start(ServerText.class, args);
15+
Solon.start(ServerTest.class, args);
1616
}
1717

1818
@Mapping("hello")
@@ -36,7 +36,7 @@ public void async_timeout(Context ctx) {
3636
}
3737

3838
@Mapping("session")
39-
public Object session(Context ctx, @Param("name") String name) {
39+
public Object session(Context ctx, @Param(value = "name",required = false) String name) {
4040
if (name == null) {
4141
return ctx.session("name");
4242
} else {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package features.jetty;
2+
3+
import org.noear.solon.annotation.Component;
4+
import org.noear.solon.annotation.Mapping;
5+
import org.noear.solon.core.handle.Context;
6+
import org.noear.solon.core.handle.Handler;
7+
8+
/**
9+
*
10+
* @author noear 2025/11/4 created
11+
*
12+
*/
13+
@Mapping("ct0")
14+
@Component
15+
public class ContentTypeHandler implements Handler {
16+
@Override
17+
public void handle(Context ctx) throws Throwable {
18+
ctx.output("hello");
19+
}
20+
}

solon-jakarta-projects/solon-server/solon-server-jetty-jakarta/src/test/java/features/jetty/ServerText.java renamed to solon-jakarta-projects/solon-server/solon-server-jetty-jakarta/src/test/java/features/jetty/ServerTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package features.jetty;
22

33
import org.junit.jupiter.api.Test;
4+
import org.noear.solon.core.util.MimeType;
45
import org.noear.solon.core.util.MultiMap;
56
import org.noear.solon.net.http.HttpResponse;
67
import org.noear.solon.test.HttpTester;
78
import org.noear.solon.test.SolonTest;
89

910
@SolonTest(App.class)
10-
public class ServerText extends HttpTester {
11+
public class ServerTest extends HttpTester {
1112

1213
@Test
1314
public void test() throws Exception {
@@ -38,4 +39,15 @@ public void session() throws Exception {
3839

3940
assert "n1".equals(path("/session").cookies(cookies).get());
4041
}
42+
43+
@Test
44+
public void ct0() {
45+
assert path("/ct0").exec("GET").contentType() == null;
46+
}
47+
48+
@Test
49+
public void ct1() {
50+
assert path("/hello").exec("GET").contentType()
51+
.startsWith(MimeType.TEXT_PLAIN_VALUE);
52+
}
4153
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package features.tomcat;
2+
3+
import org.noear.solon.Solon;
4+
import org.noear.solon.annotation.Controller;
5+
import org.noear.solon.annotation.Mapping;
6+
import org.noear.solon.annotation.Param;
7+
import org.noear.solon.core.handle.Context;
8+
9+
/**
10+
* @author noear 2024/10/1 created
11+
*/
12+
@Controller
13+
public class App {
14+
public static void main(String[] args) {
15+
Solon.start(ServerTest.class, args);
16+
}
17+
18+
@Mapping("hello")
19+
public String hello() {
20+
return "hello";
21+
}
22+
23+
@Mapping("async")
24+
public void async(Context ctx) {
25+
try {
26+
ctx.asyncStart();
27+
ctx.output("async");
28+
} finally {
29+
ctx.asyncComplete();
30+
}
31+
}
32+
33+
@Mapping("async_timeout")
34+
public void async_timeout(Context ctx) {
35+
ctx.asyncStart(100L, null);
36+
}
37+
38+
@Mapping("session")
39+
public Object session(Context ctx, @Param(value = "name",required = false) String name) {
40+
if (name == null) {
41+
return ctx.session("name");
42+
} else {
43+
ctx.sessionSet("name", name);
44+
return name;
45+
}
46+
}
47+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package features.tomcat;
2+
3+
import org.noear.solon.annotation.Component;
4+
import org.noear.solon.annotation.Mapping;
5+
import org.noear.solon.core.handle.Context;
6+
import org.noear.solon.core.handle.Handler;
7+
8+
/**
9+
*
10+
* @author noear 2025/11/4 created
11+
*
12+
*/
13+
@Mapping("ct0")
14+
@Component
15+
public class ContentTypeHandler implements Handler {
16+
@Override
17+
public void handle(Context ctx) throws Throwable {
18+
ctx.output("hello");
19+
}
20+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package features.tomcat;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.noear.solon.core.util.MimeType;
5+
import org.noear.solon.core.util.MultiMap;
6+
import org.noear.solon.net.http.HttpResponse;
7+
import org.noear.solon.test.HttpTester;
8+
import org.noear.solon.test.SolonTest;
9+
10+
@SolonTest(App.class)
11+
public class ServerTest extends HttpTester {
12+
13+
@Test
14+
public void test() throws Exception {
15+
assert "hello".equals(path("/hello").get());
16+
}
17+
18+
@Test
19+
public void async() throws Exception {
20+
assert "async".equals(path("/async").get());
21+
}
22+
23+
@Test
24+
public void async_timeout() throws Exception {
25+
assert 500 == path("/async_timeout").head();
26+
}
27+
28+
@Test
29+
public void session() throws Exception {
30+
MultiMap<String> cookies = new MultiMap<>();
31+
try (HttpResponse resp = path("/session?name=n1").exec("GET")) {
32+
assert "n1".equals(resp.bodyAsString());
33+
34+
for (String cookie : resp.cookies()) {
35+
String[] nameAndValues = cookie.split(";")[0].split("=");
36+
cookies.add(nameAndValues[0], nameAndValues[1]);
37+
}
38+
}
39+
40+
assert "n1".equals(path("/session").cookies(cookies).get());
41+
}
42+
43+
@Test
44+
public void ct0() {
45+
assert path("/ct0").exec("GET").contentType() == null;
46+
}
47+
48+
@Test
49+
public void ct1() {
50+
assert path("/hello").exec("GET").contentType()
51+
.startsWith(MimeType.TEXT_PLAIN_VALUE);
52+
}
53+
}

solon-jakarta-projects/solon-server/solon-server-undertow-jakarta/src/test/java/features/undertow/App.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
@Controller
1313
public class App {
1414
public static void main(String[] args) {
15-
Solon.start(ServerText.class, args);
15+
Solon.start(ServerTest.class, args);
1616
}
1717

1818
@Mapping("hello")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package features.undertow;
2+
3+
import org.noear.solon.annotation.Component;
4+
import org.noear.solon.annotation.Mapping;
5+
import org.noear.solon.core.handle.Context;
6+
import org.noear.solon.core.handle.Handler;
7+
8+
/**
9+
*
10+
* @author noear 2025/11/4 created
11+
*
12+
*/
13+
@Mapping("ct0")
14+
@Component
15+
public class ContentTypeHandler implements Handler {
16+
@Override
17+
public void handle(Context ctx) throws Throwable {
18+
ctx.output("hello");
19+
}
20+
}

solon-jakarta-projects/solon-server/solon-server-undertow-jakarta/src/test/java/features/undertow/ServerText.java renamed to solon-jakarta-projects/solon-server/solon-server-undertow-jakarta/src/test/java/features/undertow/ServerTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package features.undertow;
22

33
import org.junit.jupiter.api.Test;
4+
import org.noear.solon.core.util.MimeType;
45
import org.noear.solon.core.util.MultiMap;
56
import org.noear.solon.net.http.HttpResponse;
67
import org.noear.solon.test.HttpTester;
78
import org.noear.solon.test.SolonTest;
89

910
@SolonTest(App.class)
10-
public class ServerText extends HttpTester {
11+
public class ServerTest extends HttpTester {
1112

1213
@Test
1314
public void test() throws Exception {
@@ -38,4 +39,15 @@ public void session() throws Exception {
3839

3940
assert "n1".equals(path("/session").cookies(cookies).get());
4041
}
42+
43+
@Test
44+
public void ct0() {
45+
assert path("/ct0").exec("GET").contentType() == null;
46+
}
47+
48+
@Test
49+
public void ct1() {
50+
assert path("/hello").exec("GET").contentType()
51+
.startsWith(MimeType.TEXT_PLAIN_VALUE);
52+
}
4153
}

0 commit comments

Comments
 (0)