MCPcopy Create free account
hub / github.com/e2wugui/zeze / main

Method main

ZezeJava/ZezeJavaTest/src/Temp/TestHttpServer.java:9–35  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

7
8public class TestHttpServer {
9 public static void main(String[] args) throws IOException {
10 var hs = HttpServer.create(new InetSocketAddress(80), 10);
11 hs.createContext("/", he -> {
12 var sb = new StringBuilder("<html><body><pre>\n");
13 sb.append("LocalAddress: ").append(he.getLocalAddress()).append('\n');
14 sb.append("RemoteAddress: ").append(he.getRemoteAddress()).append('\n');
15 sb.append("Protocol: ").append(he.getProtocol()).append('\n');
16 sb.append("RequestMethod: ").append(he.getRequestMethod()).append('\n');
17 sb.append("RequestURI: ").append(he.getRequestURI()).append('\n');
18 sb.append("RequestHeaders:\n");
19 for (var e : he.getRequestHeaders().entrySet()) {
20 sb.append(" ").append(e.getKey()).append(": ");
21 for (String s : e.getValue())
22 sb.append(s).append(';');
23 sb.append('\n');
24 }
25 sb.append("RequestBody.length: ").append(he.getRequestBody().readAllBytes().length).append('\n');
26 sb.append("</pre></body></html>\n");
27 byte[] content = sb.toString().getBytes(StandardCharsets.UTF_8);
28 he.getResponseHeaders().add("Content-Type", "text/html; charset=utf-8");
29 he.sendResponseHeaders(200, content.length);
30 try (var os = he.getResponseBody()) {
31 os.write(content);
32 }
33 });
34 hs.start();
35 }
36}
37/*
38GET /abc/def/ HTTP/1.1

Callers

nothing calls this directly

Calls 12

createMethod · 0.65
getKeyMethod · 0.65
getValueMethod · 0.65
getBytesMethod · 0.65
addMethod · 0.65
writeMethod · 0.65
startMethod · 0.65
appendMethod · 0.45
getLocalAddressMethod · 0.45
getRemoteAddressMethod · 0.45
entrySetMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected