2020import java .io .BufferedWriter ;
2121import java .io .IOException ;
2222import java .io .OutputStream ;
23- import java .util .AbstractMap .SimpleEntry ;
2423import java .util .ArrayList ;
2524import java .util .Collection ;
2625import java .util .List ;
2726import java .util .Map ;
2827import java .util .Optional ;
28+ import java .util .TreeMap ;
2929import javax .servlet .http .HttpServletResponse ;
3030
3131public class HttpResponseImpl implements HttpResponse {
@@ -64,8 +64,12 @@ public void appendHeader(String key, String value) {
6464 @ Override
6565 public Map <String , List <String >> getHeaders () {
6666 return response .getHeaderNames ().stream ()
67- .map (header -> new SimpleEntry <>(header , list (response .getHeaders (header ))))
68- .collect (toMap (Map .Entry ::getKey , Map .Entry ::getValue ));
67+ .collect (
68+ toMap (
69+ name -> name ,
70+ name -> new ArrayList <>(response .getHeaders (name )),
71+ (a , b ) -> b ,
72+ () -> new TreeMap <>(String .CASE_INSENSITIVE_ORDER )));
6973 }
7074
7175 private static <T > List <T > list (Collection <T > collection ) {
@@ -82,12 +86,17 @@ public OutputStream getOutputStream() throws IOException {
8286 @ Override
8387 public synchronized BufferedWriter getWriter () throws IOException {
8488 if (writer == null ) {
85- // Unfortunately this means that we get two intermediate objects between the object we return
86- // and the underlying Writer that response.getWriter() wraps. We could try accessing the
87- // PrintWriter.out field via reflection, but that sort of access to non-public fields of
88- // platform classes is now frowned on and may draw warnings or even fail in subsequent
89+ // Unfortunately this means that we get two intermediate objects between the
90+ // object we return
91+ // and the underlying Writer that response.getWriter() wraps. We could try
92+ // accessing the
93+ // PrintWriter.out field via reflection, but that sort of access to non-public
94+ // fields of
95+ // platform classes is now frowned on and may draw warnings or even fail in
96+ // subsequent
8997 // versions.
90- // We could instead wrap the OutputStream, but that would require us to deduce the appropriate
98+ // We could instead wrap the OutputStream, but that would require us to deduce
99+ // the appropriate
91100 // Charset, using logic like this:
92101 // https://github.com/eclipse/jetty.project/blob/923ec38adf/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java#L731
93102 // We may end up doing that if performance is an issue.
0 commit comments