Get base content type directly rather than through Type which maybe null
This commit is contained in:
Greg Wilkins 2017-05-08 15:31:00 +02:00
parent 3495525fe1
commit b0edf18ad9
3 changed files with 12 additions and 3 deletions

View File

@ -117,7 +117,7 @@ public class ResourceHttpContent implements HttpContent
{
return _contentType==null?null:MimeTypes.CACHE.get(MimeTypes.getContentTypeWithoutCharset(_contentType));
}
/* ------------------------------------------------------------ */
@Override
public HttpField getLastModified()
@ -227,7 +227,7 @@ public class ResourceHttpContent implements HttpContent
@Override
public String toString()
{
return String.format("%s@%x{r=%s,c=%b}",this.getClass().getSimpleName(),hashCode(),_resource,_precompressedContents!=null);
return String.format("%s@%x{r=%s,ct=%s,c=%b}",this.getClass().getSimpleName(),hashCode(),_resource,_contentType,_precompressedContents!=null);
}
/* ------------------------------------------------------------ */

View File

@ -1430,9 +1430,10 @@ public class Response implements HttpServletResponse
{
if (_characterEncoding!=null &&
content.getCharacterEncoding()==null &&
content.getContentTypeValue()!=null &&
__explicitCharset.contains(_encodingFrom))
{
setContentType(content.getMimeType().getBaseType().asString());
setContentType(MimeTypes.getContentTypeWithoutCharset(content.getContentTypeValue()));
}
else
{

View File

@ -791,6 +791,8 @@ public class DefaultServletTest
FS.ensureDirExists(resBase);
File file0 = new File(resBase, "data0.txt");
createFile(file0, "Hello Text 0");
File image = new File(resBase, "image.jpg");
createFile(image, "not an image");
String resBasePath = resBase.getAbsolutePath();
@ -817,6 +819,11 @@ public class DefaultServletTest
assertResponseNotContains("Content-Length: 12", response);
assertResponseContains("Content-Type: text/plain;charset=utf-8", response);
response = connector.getResponse("GET /context/image.jpg HTTP/1.0\r\n\r\n");
assertResponseContains("Content-Length: 2", response); // 20 something long
assertResponseContains("Extra Info", response);
assertResponseContains("Content-Type: image/jpeg;charset=utf-8", response);
server.stop();
context.getServletHandler().setFilterMappings(new FilterMapping[]{});
context.getServletHandler().setFilters(new FilterHolder[]{});
@ -827,6 +834,7 @@ public class DefaultServletTest
assertResponseContains("Content-Length: 2", response); // 20 something long
assertResponseContains("Extra Info", response);
assertResponseNotContains("Content-Length: 12", response);
}