Merge remote-tracking branch 'origin/jetty-9.2.x'
This commit is contained in:
commit
5b42345cc6
|
@ -0,0 +1,51 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.embedded;
|
||||
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.handler.DefaultHandler;
|
||||
import org.eclipse.jetty.server.handler.HandlerList;
|
||||
import org.eclipse.jetty.servlet.DefaultServlet;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class JarServer
|
||||
{
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
Server server = new Server(8080);
|
||||
|
||||
ServletContextHandler context = new ServletContextHandler();
|
||||
Resource.setDefaultUseCaches(true);
|
||||
Resource base = Resource.newResource("jar:file:src/main/resources/content.jar!/");
|
||||
context.setBaseResource(base);
|
||||
context.addServlet(new ServletHolder(new DefaultServlet()), "/");
|
||||
|
||||
HandlerList handlers = new HandlerList();
|
||||
handlers.setHandlers(new Handler[] { context, new DefaultHandler() });
|
||||
server.setHandler(handlers);
|
||||
|
||||
server.start();
|
||||
server.join();
|
||||
}
|
||||
}
|
Binary file not shown.
|
@ -43,7 +43,7 @@ public enum HttpMethod
|
|||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Optimised lookup to find a method name and trailing space in a byte array.
|
||||
* Optimized lookup to find a method name and trailing space in a byte array.
|
||||
* @param bytes Array containing ISO-8859-1 characters
|
||||
* @param position The first valid index
|
||||
* @param limit The first non valid index
|
||||
|
@ -74,26 +74,26 @@ public enum HttpMethod
|
|||
break;
|
||||
case 'O':
|
||||
if (bytes[position+1]=='O' && bytes[position+2]=='T' && bytes[position+3]=='I' && length>=8 &&
|
||||
bytes[position+4]=='O' && bytes[position+5]=='N' && bytes[position+6]=='S' && bytes[position+7]==' ' )
|
||||
bytes[position+4]=='O' && bytes[position+5]=='N' && bytes[position+6]=='S' && bytes[position+7]==' ' )
|
||||
return OPTIONS;
|
||||
break;
|
||||
case 'D':
|
||||
if (bytes[position+1]=='E' && bytes[position+2]=='L' && bytes[position+3]=='E' && length>=7 &&
|
||||
bytes[position+4]=='T' && bytes[position+5]=='E' && bytes[position+6]==' ' )
|
||||
bytes[position+4]=='T' && bytes[position+5]=='E' && bytes[position+6]==' ' )
|
||||
return DELETE;
|
||||
break;
|
||||
case 'T':
|
||||
if (bytes[position+1]=='R' && bytes[position+2]=='A' && bytes[position+3]=='C' && length>=6 &&
|
||||
bytes[position+4]=='E' && bytes[position+5]==' ' )
|
||||
bytes[position+4]=='E' && bytes[position+5]==' ' )
|
||||
return TRACE;
|
||||
break;
|
||||
case 'C':
|
||||
if (bytes[position+1]=='O' && bytes[position+2]=='N' && bytes[position+3]=='N' && length>=8 &&
|
||||
bytes[position+4]=='E' && bytes[position+5]=='C' && bytes[position+6]=='T' && bytes[position+7]==' ' )
|
||||
bytes[position+4]=='E' && bytes[position+5]=='C' && bytes[position+6]=='T' && bytes[position+7]==' ' )
|
||||
return CONNECT;
|
||||
break;
|
||||
case 'M':
|
||||
if (bytes[position+1]=='O' && bytes[position+2]=='V' && bytes[position+3]=='E' && bytes[position+4]==' ')
|
||||
if (bytes[position+1]=='O' && bytes[position+2]=='V' && bytes[position+3]=='E' && length>=5 && bytes[position+4]==' ')
|
||||
return MOVE;
|
||||
break;
|
||||
|
||||
|
@ -105,17 +105,26 @@ public enum HttpMethod
|
|||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Optimised lookup to find a method name and trailing space in a byte array.
|
||||
* @param buffer buffer containing ISO-8859-1 characters
|
||||
* Optimized lookup to find a method name and trailing space in a byte array.
|
||||
* @param buffer buffer containing ISO-8859-1 characters, it is not modified.
|
||||
* @return A HttpMethod if a match or null if no easy match.
|
||||
*/
|
||||
public static HttpMethod lookAheadGet(ByteBuffer buffer)
|
||||
{
|
||||
if (buffer.hasArray())
|
||||
return lookAheadGet(buffer.array(),buffer.arrayOffset()+buffer.position(),buffer.arrayOffset()+buffer.limit());
|
||||
|
||||
// TODO use cache and check for space
|
||||
// return CACHE.getBest(buffer,0,buffer.remaining());
|
||||
|
||||
int l = buffer.remaining();
|
||||
if (l>=4)
|
||||
{
|
||||
HttpMethod m = CACHE.getBest(buffer,0,l);
|
||||
if (m!=null)
|
||||
{
|
||||
int ml = m.asString().length();
|
||||
if (l>ml && buffer.get(buffer.position()+ml)==' ')
|
||||
return m;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -162,6 +171,7 @@ public enum HttpMethod
|
|||
return toString();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Converts the given String parameter to an HttpMethod
|
||||
* @param method the String to get the equivalent HttpMethod from
|
||||
|
|
|
@ -66,6 +66,27 @@ public class HttpParserTest
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void HttpMethodTest()
|
||||
{
|
||||
assertNull(HttpMethod.lookAheadGet(BufferUtil.toBuffer("Wibble ")));
|
||||
assertNull(HttpMethod.lookAheadGet(BufferUtil.toBuffer("GET")));
|
||||
assertNull(HttpMethod.lookAheadGet(BufferUtil.toBuffer("MO")));
|
||||
|
||||
assertEquals(HttpMethod.GET,HttpMethod.lookAheadGet(BufferUtil.toBuffer("GET ")));
|
||||
assertEquals(HttpMethod.MOVE,HttpMethod.lookAheadGet(BufferUtil.toBuffer("MOVE ")));
|
||||
|
||||
ByteBuffer b = BufferUtil.allocateDirect(128);
|
||||
BufferUtil.append(b,BufferUtil.toBuffer("GET"));
|
||||
assertNull(HttpMethod.lookAheadGet(b));
|
||||
|
||||
BufferUtil.append(b,BufferUtil.toBuffer(" "));
|
||||
assertEquals(HttpMethod.GET,HttpMethod.lookAheadGet(b));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testLineParse0() throws Exception
|
||||
{
|
||||
|
|
|
@ -388,9 +388,9 @@ public class BufferUtil
|
|||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Appends a byte to a buffer
|
||||
/** Appends a buffer to a buffer
|
||||
* @param to Buffer is flush mode
|
||||
* @param b bytes to append
|
||||
* @param b buffer to append
|
||||
*/
|
||||
public static int append(ByteBuffer to, ByteBuffer b)
|
||||
{
|
||||
|
|
|
@ -136,6 +136,7 @@ class JarFileResource extends JarResource
|
|||
* Returns true if the represented resource exists.
|
||||
*/
|
||||
@Override
|
||||
|
||||
public boolean exists()
|
||||
{
|
||||
if (_exists)
|
||||
|
@ -161,10 +162,11 @@ class JarFileResource extends JarResource
|
|||
else
|
||||
{
|
||||
// Can we find a file for it?
|
||||
JarFile jarFile=null;
|
||||
boolean close_jar_file= false;
|
||||
JarFile jar_file=null;
|
||||
if (check)
|
||||
// Yes
|
||||
jarFile=_jarFile;
|
||||
jar_file=_jarFile;
|
||||
else
|
||||
{
|
||||
// No - so lets look if the root entry exists.
|
||||
|
@ -172,7 +174,8 @@ class JarFileResource extends JarResource
|
|||
{
|
||||
JarURLConnection c=(JarURLConnection)((new URL(_jarUrl)).openConnection());
|
||||
c.setUseCaches(getUseCaches());
|
||||
jarFile=c.getJarFile();
|
||||
jar_file=c.getJarFile();
|
||||
close_jar_file = !getUseCaches();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
|
@ -181,10 +184,10 @@ class JarFileResource extends JarResource
|
|||
}
|
||||
|
||||
// Do we need to look more closely?
|
||||
if (jarFile!=null && _entry==null && !_directory)
|
||||
if (jar_file!=null && _entry==null && !_directory)
|
||||
{
|
||||
// OK - we have a JarFile, lets look at the entries for our path
|
||||
Enumeration<JarEntry> e=jarFile.entries();
|
||||
Enumeration<JarEntry> e=jar_file.entries();
|
||||
while(e.hasMoreElements())
|
||||
{
|
||||
JarEntry entry = e.nextElement();
|
||||
|
@ -213,6 +216,18 @@ class JarFileResource extends JarResource
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(close_jar_file && jar_file!=null)
|
||||
{
|
||||
try
|
||||
{
|
||||
jar_file.close();
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
LOG.ignore(ioe);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_exists= ( _directory || _entry!=null);
|
||||
|
|
Loading…
Reference in New Issue