On Wed, 1 May 2024 21:12:05 GMT, robert engels <d...@openjdk.org> wrote:

>> improve the HttpExchange api with documented constants and convenience 
>> methods to avoid common bugs
>
> robert engels has updated the pull request incrementally with two additional 
> commits since the last revision:
> 
>  - Merge remote-tracking branch 'robaho/HttpExchange-api-change' into 
> HttpExchange-api-change
>    
>    # Conflicts:
>    #  
> src/jdk.httpserver/share/classes/com/sun/net/httpserver/HttpExchange.java
>  - update api changes based on comments

Noting that this design "shape" i know from the Pedestal clojure libraries, 
which also provide for an optional "default-content-type" 

http://pedestal.io/api/0.7/io.pedestal.http.impl.servlet-interceptor.html#var-WriteableBody

Which could also improve usability.


interface Body {
    OptionalInt contentLength();
    
    default Optional<String> defaultContentType() {
        return Optional.empty();
    }
    
    void writeTo(OutputStream os);
}


(then, in userland)


record JsonBody(Json json) implements Body {
   // ...
   
   public Optional<String> defaultContentType() {
        return Optional.of("application/json");
    }
}



exchange.sendResponse(200, new JsonBody(person));

-------------

PR Comment: https://git.openjdk.org/jdk/pull/18955#issuecomment-2089273729

Reply via email to