comparison src/goodjava/webserver/Response.java @ 1607:fa066aaa068c

nginx caching
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 30 Apr 2021 20:23:28 -0600
parents ef9d96aeb541
children
comparison
equal deleted inserted replaced
1606:7c7f28c724e8 1607:fa066aaa068c
4 import java.io.PrintWriter; 4 import java.io.PrintWriter;
5 import java.util.Map; 5 import java.util.Map;
6 import java.util.LinkedHashMap; 6 import java.util.LinkedHashMap;
7 import java.util.Collections; 7 import java.util.Collections;
8 import java.util.List; 8 import java.util.List;
9 import goodjava.util.CaseInsensitiveMap;
9 10
10 11
11 public class Response { 12 public class Response {
12 public final String protocol = "HTTP/1.1"; 13 public final String protocol = "HTTP/1.1";
13 public volatile Status status = Status.OK; 14 public volatile Status status = Status.OK;
14 public final Map<String,Object> headers = Collections.synchronizedMap(new LinkedHashMap<String,Object>()); 15 public final Map<String,Object> headers = Collections.synchronizedMap(new CaseInsensitiveMap<Object>(new LinkedHashMap<String,CaseInsensitiveMap.Value<Object>>()));
15 { 16 {
16 headers.put("server","goodjava"); 17 headers.put("Server","goodjava");
17 } 18 }
18 private static final Body empty = new Body(0,new InputStream(){ 19 private static final Body empty = new Body(0,new InputStream(){
19 public int read() { return -1; } 20 public int read() { return -1; }
20 }); 21 });
21 public volatile Body body = empty; 22 public volatile Body body = empty;
74 75
75 76
76 public static Response errorResponse(Status status,String text) { 77 public static Response errorResponse(Status status,String text) {
77 Response response = new Response(); 78 Response response = new Response();
78 response.status = status; 79 response.status = status;
79 response.headers.put( "content-type", "text/plain; charset=utf-8" ); 80 response.headers.put( "Content-Type", "text/plain; charset=utf-8" );
80 PrintWriter writer = new PrintWriter( new ResponseOutputStream(response) ); 81 PrintWriter writer = new PrintWriter( new ResponseOutputStream(response) );
81 writer.write( text ); 82 writer.write( text );
82 writer.close(); 83 writer.close();
83 return response; 84 return response;
84 } 85 }