Merge remote-tracking branch 'origin/jetty-9.3.x' into jetty-9.4.x

This commit is contained in:
Greg Wilkins 2016-07-29 18:03:27 +10:00
commit 06a40e919a
6 changed files with 60 additions and 39 deletions

View File

@ -28,7 +28,6 @@ import org.eclipse.jetty.deploy.bindings.DebugListenerBinding;
import org.eclipse.jetty.deploy.providers.WebAppProvider;
import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.jmx.MBeanContainer;
import org.eclipse.jetty.rewrite.handler.CompactPathRule;
import org.eclipse.jetty.rewrite.handler.RewriteHandler;
import org.eclipse.jetty.security.HashLoginService;
import org.eclipse.jetty.server.ConnectorStatistics;
@ -166,7 +165,7 @@ public class LikeJettyXml
// === jetty-deploy.xml ===
DeploymentManager deployer = new DeploymentManager();
DebugListener debug = new DebugListener(System.out,true,true,true);
DebugListener debug = new DebugListener(System.err,true,true,true);
server.addBean(debug);
deployer.addLifeCycleBinding(new DebugListenerBinding(debug));
deployer.setContexts(contexts);

View File

@ -30,6 +30,8 @@ import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import org.eclipse.jetty.util.ArrayTernaryTrie;
import org.eclipse.jetty.util.QuotedStringTokenizer;
@ -97,6 +99,11 @@ public class HttpFields implements Iterable<HttpField>
return new Itr();
}
public Stream<HttpField> stream()
{
return StreamSupport.stream(Arrays.spliterator(_fields,0,_size),false);
}
/**
* Get Collection of header names.
* @return the unique set of field names.

View File

@ -547,6 +547,11 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor
fields.put(_connector.getServer().getDateField());
_request.setMetaData(request);
if (LOG.isDebugEnabled())
LOG.debug("REQUEST for {} on {}{}{} {} {}{}{}",request.getURIString(),this,System.lineSeparator(),
request.getMethod(),request.getURIString(),request.getVersion(),System.lineSeparator(),
request.getFields());
}
public boolean onContent(HttpInput.Content content)
@ -566,6 +571,9 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor
public void onCompleted()
{
if (LOG.isDebugEnabled())
LOG.debug("COMPLETE for {} written={}",getRequest().getRequestURI(),getBytesWritten());
if (_requestLog!=null )
_requestLog.log(_request, _response);
@ -683,7 +691,9 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor
{
_committedMetaData=info;
if (LOG.isDebugEnabled())
LOG.debug("Commit {} to {}",info,this);
LOG.debug("COMMIT for {} on {}{}{} {} {}{}{}",getRequest().getRequestURI(),this,System.lineSeparator(),
info.getStatus(),info.getReason(),info.getVersion(),System.lineSeparator(),
info.getFields());
}
public boolean isCommitted()

View File

@ -1470,9 +1470,6 @@ public class Request implements HttpServletRequest
}
/* ------------------------------------------------------------ */
/**
* @see javax.servlet.http.HttpServletRequest#changeSessionId()
*/
@Override
public String changeSessionId()
{

View File

@ -27,8 +27,10 @@ import java.util.Collections;
import java.util.EnumSet;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletOutputStream;
@ -1137,15 +1139,25 @@ public class Response implements HttpServletResponse
@Override
public void reset()
{
reset(false);
}
public void reset(boolean preserveCookies)
{
resetForForward();
_status = 200;
_reason = null;
_contentLength = -1;
List<HttpField> cookies = preserveCookies
?_fields.stream()
.filter(f->f.getHeader()==HttpHeader.SET_COOKIE)
.collect(Collectors.toList()):null;
_fields.clear();
String connection = _channel.getRequest().getHeader(HttpHeader.CONNECTION.asString());
if (connection != null)
{
for (String value: StringUtil.csvSplit(null,connection,0,connection.length()))
@ -1172,21 +1184,23 @@ public class Response implements HttpServletResponse
}
}
}
}
public void reset(boolean preserveCookies)
{
if (!preserveCookies)
reset();
if (preserveCookies)
cookies.forEach(f->_fields.add(f));
else
{
ArrayList<String> cookieValues = new ArrayList<>(5);
Enumeration<String> vals = _fields.getValues(HttpHeader.SET_COOKIE.asString());
while (vals.hasMoreElements())
cookieValues.add(vals.nextElement());
reset();
for (String v:cookieValues)
_fields.add(HttpHeader.SET_COOKIE, v);
Request request = getHttpChannel().getRequest();
HttpSession session = request.getSession(false);
if (session!=null && session.isNew())
{
SessionHandler sh = request.getSessionHandler();
if (sh!=null)
{
HttpCookie c=sh.getSessionCookie(session,request.getContextPath(),request.isSecure());
if (c!=null)
addCookie(c);
}
}
}
}

View File

@ -528,15 +528,14 @@ public class Server extends HandlerWrapper implements Attributes
* or after the entire request has been received (for short requests of known length), or
* on the dispatch of an async request.
*/
public void handle(HttpChannel connection) throws IOException, ServletException
public void handle(HttpChannel channel) throws IOException, ServletException
{
final String target=connection.getRequest().getPathInfo();
final Request request=connection.getRequest();
final Response response=connection.getResponse();
final String target=channel.getRequest().getPathInfo();
final Request request=channel.getRequest();
final Response response=channel.getResponse();
if (LOG.isDebugEnabled())
LOG.debug("{} on {}{}{} {} {}{}{}", request.getDispatcherType(), connection, System.lineSeparator(),
request.getMethod(), target, request.getProtocol(), System.lineSeparator(), request.getHttpFields());
LOG.debug("{} {} {} on {}", request.getDispatcherType(), request.getMethod(), target, channel);
if (HttpMethod.OPTIONS.is(request.getMethod()) || "*".equals(target))
{
@ -550,8 +549,7 @@ public class Server extends HandlerWrapper implements Attributes
handle(target, request, request, response);
if (LOG.isDebugEnabled())
LOG.debug("RESPONSE for {} h={}{}{} {}{}{}", target, request.isHandled(), System.lineSeparator(),
response.getStatus(), response.getReason(), System.lineSeparator(), response.getHttpFields());
LOG.debug("handled={} async={} committed={} on {}", request.isHandled(),request.isAsyncStarted(),response.isCommitted(),channel);
}
/* ------------------------------------------------------------ */
@ -567,12 +565,12 @@ public class Server extends HandlerWrapper implements Attributes
* or after the entire request has been received (for short requests of known length), or
* on the dispatch of an async request.
*/
public void handleAsync(HttpChannel connection) throws IOException, ServletException
public void handleAsync(HttpChannel channel) throws IOException, ServletException
{
final HttpChannelState state = connection.getRequest().getHttpChannelState();
final HttpChannelState state = channel.getRequest().getHttpChannelState();
final AsyncContextEvent event = state.getAsyncContextEvent();
final Request baseRequest=connection.getRequest();
final Request baseRequest=channel.getRequest();
final String path=event.getPath();
if (path!=null)
@ -592,14 +590,10 @@ public class Server extends HandlerWrapper implements Attributes
final HttpServletResponse response=(HttpServletResponse)event.getSuppliedResponse();
if (LOG.isDebugEnabled())
{
LOG.debug(request.getDispatcherType()+" "+request.getMethod()+" "+target+" on "+connection);
LOG.debug("{} {} {} on {}", request.getDispatcherType(), request.getMethod(), target, channel);
handle(target, baseRequest, request, response);
LOG.debug("RESPONSE "+target+" "+connection.getResponse().getStatus());
}
else
handle(target, baseRequest, request, response);
if (LOG.isDebugEnabled())
LOG.debug("handledAsync={} async={} committed={} on {}", channel.getRequest().isHandled(),request.isAsyncStarted(),response.isCommitted(),channel);
}
/* ------------------------------------------------------------ */