minor clean ups

This commit is contained in:
Greg Wilkins 2014-06-17 15:39:55 +02:00
parent 0539b48b8a
commit 85cb290e1c
5 changed files with 79 additions and 29 deletions

View File

@ -107,6 +107,4 @@ public class HostPortHttpField extends HttpField
{
return _port;
}
}

View File

@ -601,6 +601,11 @@ public class HttpFields implements Iterable<HttpField>
_fields.add(field);
}
public void addAll(HttpFields fields)
{
_fields.addAll(fields._fields);
}
/**
* Add fields from another HttpFields instance. Single valued fields are replaced, while all
* others are added.

View File

@ -478,7 +478,6 @@ public class HttpChannel implements Runnable
_request.setUri(request.getURI());
String path;
try
{
@ -505,31 +504,8 @@ public class HttpChannel implements Runnable
}
_request.setPathInfo(info);
// TODO avoid playing in headers
for (HttpField field : request.getFields())
{
HttpHeader header=field.getHeader();
String value=field.getValue();
if (value == null)
value = "";
if (header != null)
{
switch (header)
{
case CONTENT_TYPE:
MimeTypes.Type mime = MimeTypes.CACHE.get(value);
String charset = (mime == null || mime.getCharset() == null) ? MimeTypes.getCharsetFromContentType(value) : mime.getCharset().toString();
if (charset != null)
_request.setCharacterEncodingUnchecked(charset);
break;
default:
}
}
if (field.getName()!=null)
_request.getHttpFields().add(field);
}
_request.getHttpFields().addAll(request.getFields());
// TODO make this a better field for h2 hpack generation
if (_configuration.getSendDateHeader())

View File

@ -0,0 +1,61 @@
//
// ========================================================================
// Copyright (c) 1995-2014 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.server;
import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.util.MultiException;
import org.eclipse.jetty.util.MultiPartInputStreamParser;
public class MultiPartCleanerListener implements ServletRequestListener
{
@Override
public void requestDestroyed(ServletRequestEvent sre)
{
//Clean up any tmp files created by MultiPartInputStream
MultiPartInputStreamParser mpis = (MultiPartInputStreamParser)sre.getServletRequest().getAttribute(Request.__MULTIPART_INPUT_STREAM);
if (mpis != null)
{
ContextHandler.Context context = (ContextHandler.Context)sre.getServletRequest().getAttribute(Request.__MULTIPART_CONTEXT);
//Only do the cleanup if we are exiting from the context in which a servlet parsed the multipart files
if (context == sre.getServletContext())
{
try
{
mpis.deleteParts();
}
catch (MultiException e)
{
sre.getServletContext().log("Errors deleting multipart tmp files", e);
}
}
}
}
@Override
public void requestInitialized(ServletRequestEvent sre)
{
//nothing to do, multipart config set up by ServletHolder.handle()
}
}

View File

@ -457,6 +457,8 @@ public class Request implements HttpServletRequest
@Override
public String getCharacterEncoding()
{
if (_characterEncoding==null)
getContentType();
return _characterEncoding;
}
@ -502,7 +504,15 @@ public class Request implements HttpServletRequest
@Override
public String getContentType()
{
return _fields.getStringField(HttpHeader.CONTENT_TYPE);
String content_type = _fields.getStringField(HttpHeader.CONTENT_TYPE);
if (_characterEncoding==null && content_type!=null)
{
MimeTypes.Type mime = MimeTypes.CACHE.get(content_type);
String charset = (mime == null || mime.getCharset() == null) ? MimeTypes.getCharsetFromContentType(content_type) : mime.getCharset().toString();
if (charset != null)
_characterEncoding=charset;
}
return content_type;
}
/* ------------------------------------------------------------ */