diff src/luan/webserver/handlers/ContentTypeHandler.java @ 1165:668f29bc52ea

clean up content-type
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 07 Feb 2018 23:16:12 -0700
parents 49fb4e83484f
children 7e7c2d0c3b99
line wrap: on
line diff
--- a/src/luan/webserver/handlers/ContentTypeHandler.java	Wed Feb 07 17:36:38 2018 -0700
+++ b/src/luan/webserver/handlers/ContentTypeHandler.java	Wed Feb 07 23:16:12 2018 -0700
@@ -8,8 +8,6 @@
 
 
 public class ContentTypeHandler implements Handler {
-	public final static String CONTENT_TYPE = "content-type";
-
 	private final Handler handler;
 
 	// maps extension to content-type
@@ -20,13 +18,14 @@
 	public String contentTypeForNoExtension;
 
 	public ContentTypeHandler(Handler handler) {
-		this(handler,"UTF-8");
+		this(handler,"utf-8");
 	}
 
 	public ContentTypeHandler(Handler handler,String charset) {
 		this.handler = handler;
-		String htmlType = "text/html; charset=" + charset;
-		String textType = "text/plain; charset=" + charset;
+		String attrs = charset== null ? "" : "; charset="+charset;
+		String htmlType = "text/html" + attrs;
+		String textType = "text/plain" + attrs;
 		contentTypeForNoExtension = htmlType;
 		map.put( "html", htmlType );
 		map.put( "txt", textType );
@@ -35,7 +34,7 @@
 
 	public Response handle(Request request) {
 		Response response = handler.handle(request);
-		if( response!=null && !response.headers.containsKey(CONTENT_TYPE) ) {
+		if( response!=null && !response.headers.containsKey("content-type") ) {
 			String path = request.path;
 			int iSlash = path.lastIndexOf('/');
 			int iDot = path.lastIndexOf('.');
@@ -47,7 +46,7 @@
 				type = map.get( extension.toLowerCase() );
 			}
 			if( type != null )
-				response.headers.put(CONTENT_TYPE,type);
+				response.headers.put("content-type",type);
 		}
 		return response;
 	}