mirror of
https://github.com/jetty/jetty.project.git
synced 2025-02-25 00:45:18 +00:00
Get base content type directly rather than through Type which maybe null
This commit is contained in:
parent
3495525fe1
commit
b0edf18ad9
@ -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);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user