343083 better handling of isSecure
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@3091 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
9b1f8d3889
commit
54dcc72422
|
@ -381,6 +381,16 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPo
|
|||
return false;
|
||||
}
|
||||
}
|
||||
catch(Throwable e)
|
||||
{
|
||||
// TODO remove this if it finds nothing
|
||||
Log.warn(e);
|
||||
if (e instanceof RuntimeException)
|
||||
throw (RuntimeException)e;
|
||||
if (e instanceof Error)
|
||||
throw (Error)e;
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_writeBlocked=false;
|
||||
|
|
|
@ -41,7 +41,7 @@ public class NestedConnection extends HttpConnection
|
|||
connector.getServer(),
|
||||
new NestedParser(),
|
||||
new NestedGenerator(connector.getResponseBuffers(),endp,outerResponse,nestedIn),
|
||||
new NestedRequest());
|
||||
new NestedRequest(outerRequest));
|
||||
|
||||
((NestedRequest)_request).setConnection(this);
|
||||
|
||||
|
@ -55,8 +55,6 @@ public class NestedConnection extends HttpConnection
|
|||
_request.setQueryString(outerRequest.getQueryString());
|
||||
_request.setProtocol(outerRequest.getProtocol());
|
||||
|
||||
_request.setAttribute("isSecure",new Boolean(outerRequest.isSecure()));
|
||||
|
||||
// Set the headers
|
||||
HttpFields fields = getRequestFields();
|
||||
for (Enumeration<String> e=outerRequest.getHeaderNames();e.hasMoreElements();)
|
||||
|
@ -66,14 +64,23 @@ public class NestedConnection extends HttpConnection
|
|||
fields.add(header,value);
|
||||
}
|
||||
|
||||
// Slight hack for cloud foundry
|
||||
if (!fields.containsKey("x-forwarded-for") && outerRequest.getHeader("x-forwarded_for")!=null)
|
||||
fields.add("x-forwarded-for",outerRequest.getHeader("x-forwarded_for"));
|
||||
|
||||
// Let outer parse the cookies
|
||||
_request.setCookies(outerRequest.getCookies());
|
||||
|
||||
// copy request attributes
|
||||
for (Enumeration<String> e=outerRequest.getAttributeNames();e.hasMoreElements();)
|
||||
{
|
||||
String attr=e.nextElement();
|
||||
_request.setAttribute(attr,outerRequest.getAttribute(attr));
|
||||
}
|
||||
|
||||
// customize the request
|
||||
connector.customize(endp,_request);
|
||||
|
||||
// System.err.println(_request.getMethod()+" "+_request.getUri()+" "+_request.getProtocol());
|
||||
// System.err.println(fields.toString());
|
||||
}
|
||||
|
|
|
@ -20,8 +20,10 @@ import javax.servlet.ServletResponse;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.io.EndPoint;
|
||||
import org.eclipse.jetty.server.AbstractConnector;
|
||||
import org.eclipse.jetty.server.Connector;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
|
||||
/**
|
||||
* Nested Jetty Connector
|
||||
|
@ -37,6 +39,7 @@ public class NestedConnector extends AbstractConnector
|
|||
public NestedConnector()
|
||||
{
|
||||
setAcceptors(0);
|
||||
setForwarded(true);
|
||||
}
|
||||
|
||||
public void open() throws IOException
|
||||
|
|
|
@ -13,16 +13,28 @@
|
|||
package org.eclipse.jetty.nested;
|
||||
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.eclipse.jetty.server.Request;
|
||||
|
||||
public class NestedRequest extends Request
|
||||
{
|
||||
public NestedRequest()
|
||||
private final HttpServletRequest _outer;
|
||||
|
||||
public NestedRequest(HttpServletRequest outer)
|
||||
{
|
||||
_outer=outer;
|
||||
}
|
||||
|
||||
void setConnection(NestedConnection connection)
|
||||
{
|
||||
super.setConnection(connection);
|
||||
}
|
||||
|
||||
public boolean isSecure()
|
||||
{
|
||||
return _outer.isSecure();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,185 @@
|
|||
package org.eclipse.jetty.nested;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.util.IO;
|
||||
import org.eclipse.jetty.util.TypeUtil;
|
||||
|
||||
public class TestServlet extends HttpServlet
|
||||
{
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||
*/
|
||||
@Override
|
||||
protected void doGet(final HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
|
||||
{
|
||||
resp.setContentType("text/plain");
|
||||
final PrintStream out = new PrintStream(resp.getOutputStream());
|
||||
|
||||
out.println("Try out evil things.");
|
||||
|
||||
try
|
||||
{
|
||||
out.println("\nList home dir...");
|
||||
for (File f : new File("/home").listFiles())
|
||||
out.println(f);
|
||||
}
|
||||
catch(Throwable e)
|
||||
{
|
||||
e.printStackTrace(out);
|
||||
}
|
||||
try
|
||||
{
|
||||
out.println("\nList tmp dir...");
|
||||
for (File f : new File("/var/tmp").listFiles())
|
||||
out.println(f);
|
||||
}
|
||||
catch(Throwable e)
|
||||
{
|
||||
e.printStackTrace(out);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
out.println("\nCreate a /var/tmp file...");
|
||||
File file = new File("/var/tmp/eviltest");
|
||||
|
||||
out.println(file+" exists="+file.exists());
|
||||
file.createNewFile();
|
||||
file.deleteOnExit();
|
||||
out.println(file+" exists="+file.exists());
|
||||
file.delete();
|
||||
}
|
||||
catch(Throwable e)
|
||||
{
|
||||
e.printStackTrace(out);
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
out.println("\nOpen a localhost server socket ...");
|
||||
|
||||
ServerSocket socket = new ServerSocket();
|
||||
socket.bind(new InetSocketAddress("localhost",0));
|
||||
out.println("local port = "+socket.getLocalPort());
|
||||
}
|
||||
catch(Throwable e)
|
||||
{
|
||||
e.printStackTrace(out);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
out.println("\nOpen a any server socket ...");
|
||||
|
||||
ServerSocket socket = new ServerSocket();
|
||||
socket.bind(new InetSocketAddress(0));
|
||||
out.println("local port = "+socket.getLocalPort());
|
||||
}
|
||||
catch(Throwable e)
|
||||
{
|
||||
e.printStackTrace(out);
|
||||
}
|
||||
try
|
||||
{
|
||||
out.println("\nTalk to any server socket ...");
|
||||
|
||||
final ServerSocket server = new ServerSocket();
|
||||
server.bind(new InetSocketAddress(0));
|
||||
out.println("local port = "+server.getLocalPort());
|
||||
final int port = server.getLocalPort();
|
||||
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
|
||||
new Thread()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
Socket inbound = server.accept();
|
||||
out.println("accepted "+inbound);
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(inbound.getInputStream()));
|
||||
String data= in.readLine();
|
||||
out.println("read "+data);
|
||||
}
|
||||
catch(Throwable e)
|
||||
{
|
||||
e.printStackTrace(out);
|
||||
}
|
||||
finally
|
||||
{
|
||||
latch.countDown();
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
|
||||
|
||||
Socket socket = new Socket("localhost",port);
|
||||
socket.getOutputStream().write("Hello World\n".getBytes());
|
||||
|
||||
latch.await();
|
||||
socket.close();
|
||||
}
|
||||
catch(Throwable e)
|
||||
{
|
||||
e.printStackTrace(out);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
out.println("\nRead to own content ...");
|
||||
out.println("Real path / = "+getServletContext().getRealPath("/"));
|
||||
|
||||
for (File f : new File(getServletContext().getRealPath("/")).listFiles())
|
||||
out.println(f);
|
||||
|
||||
}
|
||||
catch(Throwable e)
|
||||
{
|
||||
e.printStackTrace(out);
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
out.println("\nWrite own content ...");
|
||||
|
||||
File wibble = new File(getServletContext().getRealPath("/wibble.txt"));
|
||||
if (!wibble.exists())
|
||||
wibble.createNewFile();
|
||||
|
||||
for (File f : new File(getServletContext().getRealPath("/")).listFiles())
|
||||
out.println(f);
|
||||
|
||||
}
|
||||
catch(Throwable e)
|
||||
{
|
||||
e.printStackTrace(out);
|
||||
}
|
||||
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -29,6 +29,24 @@
|
|||
<url-pattern>/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>test</servlet-name>
|
||||
<servlet-class>org.eclipse.jetty.nested.TestServlet</servlet-class>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>test</servlet-name>
|
||||
<url-pattern>/test/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>dump</servlet-name>
|
||||
<servlet-class>org.eclipse.jetty.nested.Dump</servlet-class>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>dump</servlet-name>
|
||||
<url-pattern>/outer/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
</web-app>
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue