402316 - HttpReceiver and null pointer exception.

The NPE was caused by (invalid) Set-Cookie headers without value.
A guard has been added to avoid the NPE.
This commit is contained in:
Simone Bordet 2013-03-04 15:39:10 +01:00
parent 1aa8fce78b
commit a1560bea21
2 changed files with 28 additions and 4 deletions

View File

@ -212,9 +212,13 @@ public class HttpReceiver implements HttpParser.ResponseHandler<ByteBuffer>
{
try
{
Map<String, List<String>> header = new HashMap<>(1);
header.put(field.getHeader().asString(), Collections.singletonList(field.getValue()));
connection.getHttpClient().getCookieManager().put(uri, header);
String value = field.getValue();
if (value != null)
{
Map<String, List<String>> header = new HashMap<>(1);
header.put(field.getHeader().asString(), Collections.singletonList(value));
connection.getHttpClient().getCookieManager().put(uri, header);
}
}
catch (IOException x)
{

View File

@ -22,12 +22,12 @@ import java.io.IOException;
import java.net.HttpCookie;
import java.net.URI;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.api.Response;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
@ -101,4 +101,24 @@ public class HttpCookieTest extends AbstractHttpClientServerTest
Response response = client.GET(scheme + "://" + host + ":" + port + path);
Assert.assertEquals(200, response.getStatus());
}
@Test
public void test_CookieWithoutValue() throws Exception
{
start(new AbstractHandler()
{
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
baseRequest.setHandled(true);
response.addHeader("Set-Cookie", "");
}
});
ContentResponse response = client.newRequest("localhost", connector.getLocalPort())
.scheme(scheme)
.send();
Assert.assertEquals(200, response.getStatus());
Assert.assertTrue(client.getCookieStore().getCookies().isEmpty());
}
}