10
10
11
11
import java .io .OutputStream ;
12
12
import java .nio .charset .StandardCharsets ;
13
+ import java .time .Instant ;
13
14
import java .time .ZoneId ;
14
15
import java .time .format .DateTimeFormatter ;
15
16
import java .util .ArrayList ;
@@ -22,6 +23,8 @@ public class HTTPPayload {
22
23
public static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter .ofPattern ("EEE, dd MMM yyyy HH:mm:ss z" , Locale .ENGLISH ).withZone (ZoneId .of ("GMT" ));
23
24
private static final byte [] CRLF = "\r \n " .getBytes (StandardCharsets .UTF_8 );
24
25
26
+ private final String serverName ;
27
+ private final Instant serverTime ;
25
28
private HTTPStatus status = HTTPStatus .NO_CONTENT ;
26
29
private final List <Header > headers = new ArrayList <>();
27
30
private String cacheControl = "" ;
@@ -30,6 +33,11 @@ public class HTTPPayload {
30
33
private WSSession <?> wsSession = null ;
31
34
private List <ResponseContentEncoding > encodings ;
32
35
36
+ public HTTPPayload (String serverName , Instant serverTime ) {
37
+ this .serverName = serverName ;
38
+ this .serverTime = serverTime ;
39
+ }
40
+
33
41
public void setStatus (HTTPStatus status ) {
34
42
this .status = status ;
35
43
}
@@ -111,7 +119,7 @@ public void addEncoding(ResponseContentEncoding encoding) {
111
119
encodings .add (encoding );
112
120
}
113
121
114
- public void setResponse (HTTPResponse response ) throws Exception {
122
+ public void setResponse (HTTPResponse response ) {
115
123
response .build (this );
116
124
117
125
if (response instanceof WSResponse res ) {
@@ -124,6 +132,13 @@ public void write(HTTPRequest req, OutputStream out, boolean writeBody) throws E
124
132
out .write (CRLF );
125
133
126
134
var actualHeaders = new ArrayList <Header >(headers .size () + (cookies == null ? 0 : cookies .size ()) + (cacheControl .isEmpty () ? 0 : 1 ));
135
+
136
+ if (serverName != null && !serverName .isEmpty ()) {
137
+ actualHeaders .add (new Header ("Server" , serverName ));
138
+ }
139
+
140
+ actualHeaders .add (new Header ("Date" , HTTPPayload .DATE_TIME_FORMATTER .format (serverTime )));
141
+
127
142
actualHeaders .addAll (headers );
128
143
129
144
if (cookies != null ) {
0 commit comments