Merge remote-tracking branch 'origin/jetty-7' into jetty-8
This commit is contained in:
commit
23e41673bf
|
@ -971,7 +971,9 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
|
|||
// content-length header
|
||||
//
|
||||
writeHeaders(response,content,-1);
|
||||
String mimetype=content.getContentType().toString();
|
||||
String mimetype=(content.getContentType()==null?null:content.getContentType().toString());
|
||||
if (mimetype==null)
|
||||
LOG.warn("Unknown mimetype for "+request.getRequestURI());
|
||||
MultiPartOutputStream multi = new MultiPartOutputStream(out);
|
||||
response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
|
||||
|
||||
|
@ -998,7 +1000,7 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
|
|||
length+=
|
||||
((i>0)?2:0)+
|
||||
2+multi.getBoundary().length()+2+
|
||||
HttpHeaders.CONTENT_TYPE.length()+2+mimetype.length()+2+
|
||||
(mimetype==null?0:HttpHeaders.CONTENT_TYPE.length()+2+mimetype.length())+2+
|
||||
HttpHeaders.CONTENT_RANGE.length()+2+header[i].length()+2+
|
||||
2+
|
||||
(ibr.getLast(content_length)-ibr.getFirst(content_length))+1;
|
||||
|
|
|
@ -544,8 +544,64 @@ public class DefaultServletTest
|
|||
assertResponseContains("Content-Range: bytes 70-79/80", response);
|
||||
assertResponseContains("Content-Length: " + body.length(), response);
|
||||
assertTrue(body.endsWith(boundary + "--\r\n"));
|
||||
|
||||
//test a range request with a file with no suffix, therefore no mimetype
|
||||
File nofilesuffix = new File(resBase, "nofilesuffix");
|
||||
createFile(nofilesuffix, "01234567890123456789012345678901234567890123456789012345678901234567890123456789");
|
||||
response = connector.getResponses(
|
||||
"GET /context/nofilesuffix HTTP/1.1\r\n" +
|
||||
"Host: localhost\r\n" +
|
||||
"\r\n");
|
||||
assertResponseContains("200 OK", response);
|
||||
assertResponseContains("Accept-Ranges: bytes", response);
|
||||
|
||||
response = connector.getResponses(
|
||||
"GET /context/nofilesuffix HTTP/1.1\r\n" +
|
||||
"Host: localhost\r\n" +
|
||||
"Range: bytes=0-9\r\n" +
|
||||
"\r\n");
|
||||
assertResponseContains("206 Partial", response);
|
||||
assertResponseContains("Content-Length: 10", response);
|
||||
assertTrue(!response.contains("Content-Type:"));
|
||||
assertResponseContains("Content-Range: bytes 0-9/80", response);
|
||||
|
||||
response = connector.getResponses(
|
||||
"GET /context/nofilesuffix HTTP/1.1\r\n" +
|
||||
"Host: localhost\r\n" +
|
||||
"Range: bytes=0-9,20-29,40-49\r\n" +
|
||||
"\r\n");
|
||||
start = response.indexOf("--jetty");
|
||||
body = response.substring(start);
|
||||
boundary = body.substring(0, body.indexOf("\r\n"));
|
||||
assertResponseContains("206 Partial", response);
|
||||
assertResponseContains("Content-Type: multipart/byteranges; boundary=", response);
|
||||
assertResponseContains("Content-Range: bytes 0-9/80", response);
|
||||
assertResponseContains("Content-Range: bytes 20-29/80", response);
|
||||
assertResponseContains("Content-Length: " + body.length(), response);
|
||||
assertTrue(body.endsWith(boundary + "--\r\n"));
|
||||
|
||||
response = connector.getResponses(
|
||||
"GET /context/nofilesuffix HTTP/1.1\r\n" +
|
||||
"Host: localhost\r\n" +
|
||||
"Range: bytes=0-9,20-29,40-49,60-60,70-79\r\n" +
|
||||
"\r\n");
|
||||
start = response.indexOf("--jetty");
|
||||
body = response.substring(start);
|
||||
boundary = body.substring(0, body.indexOf("\r\n"));
|
||||
assertResponseContains("206 Partial", response);
|
||||
assertResponseContains("Content-Type: multipart/byteranges; boundary=", response);
|
||||
assertResponseContains("Content-Range: bytes 0-9/80", response);
|
||||
assertResponseContains("Content-Range: bytes 20-29/80", response);
|
||||
assertResponseContains("Content-Range: bytes 60-60/80", response);
|
||||
assertResponseContains("Content-Range: bytes 70-79/80", response);
|
||||
assertResponseContains("Content-Length: " + body.length(), response);
|
||||
assertTrue(body.endsWith(boundary + "--\r\n"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testFiltered() throws Exception
|
||||
{
|
||||
|
|
|
@ -98,6 +98,7 @@ public class MultiPartOutputStream extends FilterOutputStream
|
|||
out.write(__DASHDASH);
|
||||
out.write(boundaryBytes);
|
||||
out.write(__CRLF);
|
||||
if (contentType != null)
|
||||
out.write(("Content-Type: "+contentType).getBytes(StringUtil.__ISO_8859_1));
|
||||
out.write(__CRLF);
|
||||
out.write(__CRLF);
|
||||
|
@ -115,6 +116,7 @@ public class MultiPartOutputStream extends FilterOutputStream
|
|||
out.write(__DASHDASH);
|
||||
out.write(boundaryBytes);
|
||||
out.write(__CRLF);
|
||||
if (contentType != null)
|
||||
out.write(("Content-Type: "+contentType).getBytes(StringUtil.__ISO_8859_1));
|
||||
out.write(__CRLF);
|
||||
for (int i=0;headers!=null && i<headers.length;i++)
|
||||
|
|
Loading…
Reference in New Issue