@@ -44,6 +44,7 @@ public abstract class WebServer {
4444 private static final int SC_NOT_AUTHORISED = 401 ;
4545 private static final int SC_NOT_FOUND = 404 ;
4646 private static final ExecutorService THREAD_POOL = Executors .newCachedThreadPool ();
47+ private static final String TEXT_HTML = "text/html" ;
4748
4849 public WebServer () {
4950 super ();
@@ -641,24 +642,35 @@ public class Response {
641642 private final InputStream inputStream ;
642643 private final long length ;
643644 private final int errorCode ;
645+ private final String contentType ;
646+
647+ public Response (InputStream inputStream , long length , String contentType ) {
648+ this .inputStream = inputStream ;
649+ this .length = length ;
650+ this .errorCode = SC_OKAY ;
651+ this .contentType = contentType ;
652+ }
644653
645654 public Response (InputStream inputStream , long length ) {
646655 this .inputStream = inputStream ;
647656 this .length = length ;
648657 this .errorCode = SC_OKAY ;
658+ this .contentType = TEXT_HTML ;
649659 }
650660
651661 public Response (byte [] bytes ) {
652662 this .inputStream = new ByteArrayInputStream (bytes );
653663 this .length = bytes .length ;
654664 this .errorCode = SC_OKAY ;
665+ this .contentType = TEXT_HTML ;
655666 }
656667
657668 public Response (int errorCode ) throws IOException {
658669 byte [] bytes = ("Error: " + errorCode ).getBytes (UTF_8 );
659670 this .inputStream = new ByteArrayInputStream (bytes );
660671 this .length = bytes .length ;
661672 this .errorCode = errorCode ;
673+ this .contentType = TEXT_HTML ;
662674 }
663675
664676 /**
@@ -670,7 +682,7 @@ void send(Socket socket, String cookie) throws IOException {
670682 BufferedOutputStream out = new BufferedOutputStream (socket .getOutputStream ());
671683 String code = errorCode == SC_OKAY ? SC_OKAY + " OK" : String .valueOf (errorCode );
672684 out .write (("HTTP/1.0 " + code + "\r \n " ).getBytes (UTF_8 ));
673- out .write ("Content-type: text/html \r \n " .getBytes (UTF_8 ));
685+ out .write (( "Content-type: " + contentType + " \r \n ") .getBytes (UTF_8 ));
674686 out .write (contentLength .getBytes (UTF_8 ));
675687 if (cookie != null ) {
676688 out .write (("Set-Cookie: " + TOKEN + "=" + cookie + "\r \n " ).getBytes (UTF_8 ));
0 commit comments