On Thu, 25 Apr 2024 15:49:54 GMT, robert engels <d...@openjdk.org> wrote:
> improve the HttpExchange api with documented constants and convenience > methods to avoid common bugs Changes requested by michaelm (Reviewer). src/jdk.httpserver/share/classes/com/sun/net/httpserver/HttpExchange.java line 74: > 72: public abstract class HttpExchange implements AutoCloseable, Request { > 73: /** > 74: * use in sendResponseHeaders() to signify no content in the response. Suggestion: * Use in sendResponseHeaders() to signify no content in the response. src/jdk.httpserver/share/classes/com/sun/net/httpserver/HttpExchange.java line 80: > 78: /** > 79: * use in sendResponseHeaders() to signify an indeterminate response > length. The caller must > 80: * close the getResponseBody() or this exchange. Suggestion: * Use in sendResponseHeaders() to signify an indeterminate response length. src/jdk.httpserver/share/classes/com/sun/net/httpserver/HttpExchange.java line 219: > 217: > 218: /** > 219: * convenience method to send a "no content response" Suggestion: * Convenience method to send the response headers with no response body. * The exchange is also closed. src/jdk.httpserver/share/classes/com/sun/net/httpserver/HttpExchange.java line 225: > 223: */ > 224: public final void sendResponseHeadersNoContent(int code) throws > IOException { > 225: sendResponseHeaders(code,NO_CONTENT); Suggestion: sendResponseHeaders(code, NO_CONTENT); close(); src/jdk.httpserver/share/classes/com/sun/net/httpserver/HttpExchange.java line 228: > 226: } > 227: /** > 228: * convenience method to send a chunked response. the caller must > close the returned output stream. Suggestion: * Convenience method to send a chunked response. The caller must write the response * body to the returned output stream and then close it. src/jdk.httpserver/share/classes/com/sun/net/httpserver/HttpExchange.java line 246: > 244: * @see HttpExchange#sendResponseHeaders(int, long) > 245: */ > 246: public final void sendResponseHeaders(int code,byte[] data) throws > IOException { I'd prefer to drop this method. Some time in the future we might come up with a better mechanism for handling request and response bodies and translating them to higher level types. ------------- PR Review: https://git.openjdk.org/jdk/pull/18955#pullrequestreview-2025238367 PR Review Comment: https://git.openjdk.org/jdk/pull/18955#discussion_r1581152653 PR Review Comment: https://git.openjdk.org/jdk/pull/18955#discussion_r1581155836 PR Review Comment: https://git.openjdk.org/jdk/pull/18955#discussion_r1581146115 PR Review Comment: https://git.openjdk.org/jdk/pull/18955#discussion_r1581147127 PR Review Comment: https://git.openjdk.org/jdk/pull/18955#discussion_r1581149586 PR Review Comment: https://git.openjdk.org/jdk/pull/18955#discussion_r1581152077