@@ -23,7 +23,6 @@ public ResponseWriter(OutputStream outputStream) {
2323 public void write (Response response ) {
2424 try {
2525 writeStatusCode (response );
26- writeContentLengthHeader (response );
2726 writeHeaders (response );
2827 writeEmptyLine ();
2928 writePayload (response );
@@ -36,16 +35,18 @@ private void writeStatusCode(Response response) throws IOException {
3635 write (statusLine (response .getStatusCode ()).getBytes ());
3736 }
3837
39- private void writeContentLengthHeader (Response response ) throws IOException {
40- write (contentLengthHeader (response .getPayload ()).getBytes ());
41- }
42-
4338 private void writeHeaders (Response response ) throws IOException {
39+ writeContentLengthHeader (response );
4440 for (Header header : response .getHeaders ()) {
4541 write ((header .toString () + "\r \n " ).getBytes ());
4642 }
4743 }
4844
45+ private void writeContentLengthHeader (Response response ) throws IOException {
46+ String header = response .getContentLengthHeader ().toString () + "\r \n " ;
47+ write (header .getBytes ());
48+ }
49+
4950 private void writeEmptyLine () throws IOException {
5051 write (("\r \n " ).getBytes ());
5152 }
@@ -58,10 +59,6 @@ private void write(byte[] bytes) throws IOException {
5859 outputStream .write (bytes );
5960 }
6061
61- private String contentLengthHeader (byte [] payload ) {
62- return "Content-Length: " + payload .length + "\r \n " ;
63- }
64-
6562 private String statusLine (int statusCode ) {
6663 return ("HTTP/1.1 " + statusCode
6764 + " " + statuses .get (statusCode )
0 commit comments