297104 Improve handling of CONNECT method

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@1489 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Greg Wilkins 2010-04-08 12:19:03 +00:00
parent 6176ea23c4
commit b82adb9e79
5 changed files with 147 additions and 3 deletions

View File

@ -1,6 +1,7 @@
jetty-7.1-SNAPSHOT
+ 294563 Websocket client connection
+ 297104 Improve handling of CONNECT method
+ 306349 ProxyServlet does not work unless deployed at /
+ 307847 Fixed combining mime type parameters
+ 307898 Handle large/async websocket messages

View File

@ -15,6 +15,8 @@ package org.eclipse.jetty.http;
import java.io.UnsupportedEncodingException;
import javax.net.ssl.HostnameVerifier;
import org.eclipse.jetty.util.MultiMap;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.TypeUtil;
@ -110,6 +112,80 @@ public class HttpURI
parse2(raw,offset,length);
}
public void parseConnect(byte[] raw,int offset, int length)
{
_rawString=null;
_encoded=false;
_raw=raw;
int i=offset;
int e=offset+length;
int state=AUTH;
int m=offset;
_end=offset+length;
_scheme=offset;
_authority=offset;
_host=offset;
_port=_end;
_portValue=-1;
_path=_end;
_param=_end;
_query=_end;
_fragment=_end;
loop: while (i<e)
{
char c=(char)(0xff&_raw[i]);
int s=i++;
switch (state)
{
case AUTH:
{
switch (c)
{
case ':':
{
_port = s;
break loop;
}
case '[':
{
state = IPV6;
break;
}
}
continue;
}
case IPV6:
{
switch (c)
{
case '/':
{
throw new IllegalArgumentException("No closing ']' for " + StringUtil.toString(_raw,offset,length,URIUtil.__CHARSET));
}
case ']':
{
state = AUTH;
break;
}
}
continue;
}
}
}
if (_port<_path)
_portValue=TypeUtil.parseInt(_raw, _port+1, _path-_port-1,10);
else
throw new IllegalArgumentException("No port");
_path=offset;
}
private void parse2(byte[] raw,int offset, int length)
{
_encoded=false;

View File

@ -836,7 +836,20 @@ public class HttpConnection implements Connection
try
{
_uri.parse(uri.array(), uri.getIndex(), uri.length());
switch (HttpMethods.CACHE.getOrdinal(method))
{
case HttpMethods.CONNECT_ORDINAL:
_uri.parseConnect(uri.array(), uri.getIndex(), uri.length());
break;
case HttpMethods.HEAD_ORDINAL:
_head=true;
// fall through
default:
_uri.parse(uri.array(), uri.getIndex(), uri.length());
}
_request.setUri(_uri);
if (version==null)
@ -851,8 +864,6 @@ public class HttpConnection implements Connection
if (_version <= 0) _version = HttpVersions.HTTP_1_0_ORDINAL;
_request.setProtocol(version.toString());
}
_head = method == HttpMethods.HEAD_BUFFER; // depends on method being decached.
}
catch (Exception e)
{

View File

@ -491,6 +491,31 @@ public class HttpConnectionTest extends TestCase
}
}
public void testCONNECT()
{
String response = null;
try
{
int offset=0;
response=connector.getResponses("CONNECT www.webtide.com:8080 HTTP/1.1\n"+
"Host: myproxy:8888\015\012"+
"\015\012");
System.err.println("RESPONSE:"+response);
offset = checkContains(response,offset,"HTTP/1.1 200");
}
catch (Exception e)
{
e.printStackTrace();
assertTrue(false);
if (response!=null)
System.err.println(response);
}
}
private int checkContains(String s,int offset,String c)
{

View File

@ -16,6 +16,7 @@ package org.eclipse.jetty.server;
import junit.framework.TestCase;
import org.eclipse.jetty.http.HttpURI;
import org.eclipse.jetty.io.ByteArrayBuffer;
public class HttpURITest extends TestCase
{
@ -185,4 +186,34 @@ public class HttpURITest extends TestCase
}
}
String[][] connect_tests=
{
/* 0*/ {" localhost:8080 ","localhost","8080"},
/* 1*/ {" 127.0.0.1:8080 ","127.0.0.1","8080"},
/* 2*/ {" [127::0::0::1]:8080 ","[127::0::0::1]","8080"},
/* 3*/ {" error ",null,null},
/* 4*/ {" http://localhost:8080/ ",null,null},
};
public void testCONNECT()
throws Exception
{
HttpURI uri = new HttpURI();
for (int i=0;i<connect_tests.length;i++)
{
try
{
ByteArrayBuffer buf = new ByteArrayBuffer(connect_tests[i][0]);
uri.parseConnect(buf.array(),2,buf.length()-4);
assertEquals("path"+i,connect_tests[i][1]+":"+connect_tests[i][2],uri.getPath());
assertEquals("host"+i,connect_tests[i][1],uri.getHost());
assertEquals("port"+i,Integer.parseInt(connect_tests[i][2]),uri.getPort());
}
catch(Exception e)
{
assertNull("error"+i,connect_tests[i][1]);
}
}
}
}