|
27 | 27 | import java.nio.file.StandardOpenOption; |
28 | 28 | import java.util.ArrayList; |
29 | 29 | import java.util.Base64; |
| 30 | +import java.util.Collection; |
30 | 31 | import java.util.Collections; |
31 | 32 | import java.util.List; |
32 | 33 | import java.util.Map; |
|
60 | 61 | import org.eclipse.jetty.http3.server.HTTP3ServerQuicConfiguration; |
61 | 62 | import org.eclipse.jetty.io.ByteBufferPool; |
62 | 63 | import org.eclipse.jetty.io.Content; |
| 64 | +import org.eclipse.jetty.io.DatagramChannelEndPoint; |
| 65 | +import org.eclipse.jetty.io.EndPoint; |
63 | 66 | import org.eclipse.jetty.quic.quiche.server.QuicheServerConnector; |
64 | 67 | import org.eclipse.jetty.quic.quiche.server.QuicheServerQuicConfiguration; |
65 | 68 | import org.eclipse.jetty.server.Handler; |
@@ -189,6 +192,8 @@ public enum ChecksumHeader { |
189 | 192 |
|
190 | 193 | private final List<LogEntry> logEntries = Collections.synchronizedList(new ArrayList<>()); |
191 | 194 |
|
| 195 | + private String responseBodyForPut; |
| 196 | + |
192 | 197 | public String getHost() { |
193 | 198 | return "localhost"; |
194 | 199 | } |
@@ -323,6 +328,11 @@ public HttpServer setRangeSupport(boolean rangeSupport) { |
323 | 328 | return this; |
324 | 329 | } |
325 | 330 |
|
| 331 | + public HttpServer setResponseBodyForPut(String body) { |
| 332 | + this.responseBodyForPut = body; |
| 333 | + return this; |
| 334 | + } |
| 335 | + |
326 | 336 | public HttpServer setWebDav(boolean webDav) { |
327 | 337 | this.webDav = webDav; |
328 | 338 | return this; |
@@ -397,6 +407,27 @@ public void stop() throws Exception { |
397 | 407 | } |
398 | 408 | } |
399 | 409 |
|
| 410 | + public int getNumConnectedEndPoints() { |
| 411 | + if (server.isStopped()) { |
| 412 | + throw new IllegalStateException("Server is stopped"); |
| 413 | + } |
| 414 | + Collection<EndPoint> connectedEndPoints = new ArrayList<>(); |
| 415 | + if (httpConnector != null) { |
| 416 | + connectedEndPoints.addAll(httpConnector.getConnectedEndPoints()); |
| 417 | + } |
| 418 | + if (httpsConnector != null) { |
| 419 | + connectedEndPoints.addAll(httpsConnector.getConnectedEndPoints()); |
| 420 | + } |
| 421 | + if (http3Connector != null) { |
| 422 | + // filter out the always present DatagramChannelEndPoint, which is not a real live connection |
| 423 | + // (https://github.com/jetty/jetty.project/issues/15436) |
| 424 | + http3Connector.getConnectedEndPoints().stream() |
| 425 | + .filter(endPoint -> !(endPoint instanceof DatagramChannelEndPoint)) |
| 426 | + .forEach(connectedEndPoints::add); |
| 427 | + } |
| 428 | + return connectedEndPoints.size(); |
| 429 | + } |
| 430 | + |
400 | 431 | private class CompressionEnforcingHandler extends CompressionHandler { |
401 | 432 | // duplicate of CompressionHandler.pathConfigs which is private |
402 | 433 | private final PathMappings<CompressionConfig> pathConfigs = new PathMappings<>(); |
@@ -662,7 +693,14 @@ public boolean handle(Request req, Response response, Callback callback) throws |
662 | 693 | file.delete(); |
663 | 694 | throw e; |
664 | 695 | } |
665 | | - response.setStatus(HttpServletResponse.SC_NO_CONTENT); |
| 696 | + // optionally add some response body to test that the client can handle it, even though Maven |
| 697 | + // Repository Protocol doesn't mention it |
| 698 | + if (responseBodyForPut != null) { |
| 699 | + writeResponseBodyMessage(req, response, responseBodyForPut); |
| 700 | + response.setStatus(HttpServletResponse.SC_CREATED); |
| 701 | + } else { |
| 702 | + response.setStatus(HttpServletResponse.SC_NO_CONTENT); |
| 703 | + } |
666 | 704 | } else { |
667 | 705 | response.setStatus(HttpServletResponse.SC_FORBIDDEN); |
668 | 706 | } |
|
0 commit comments