Re-synched HttpClient trunk with HttpCore trunk
git-svn-id: https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpclient/trunk@595948 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3ddce358ae
commit
a543fc4fff
|
@ -63,7 +63,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.httpcomponents</groupId>
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
<artifactId>httpcore</artifactId>
|
<artifactId>httpcore</artifactId>
|
||||||
<version>4.0-alpha6</version>
|
<version>4.0-alpha7-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-logging</groupId>
|
<groupId>commons-logging</groupId>
|
||||||
|
|
|
@ -40,6 +40,8 @@ import org.apache.http.auth.AuthScheme;
|
||||||
import org.apache.http.auth.AUTH;
|
import org.apache.http.auth.AUTH;
|
||||||
import org.apache.http.auth.MalformedChallengeException;
|
import org.apache.http.auth.MalformedChallengeException;
|
||||||
import org.apache.http.message.BasicHeaderValueParser;
|
import org.apache.http.message.BasicHeaderValueParser;
|
||||||
|
import org.apache.http.message.HeaderValueParser;
|
||||||
|
import org.apache.http.message.ParserCursor;
|
||||||
import org.apache.http.protocol.HTTP;
|
import org.apache.http.protocol.HTTP;
|
||||||
import org.apache.http.util.CharArrayBuffer;
|
import org.apache.http.util.CharArrayBuffer;
|
||||||
|
|
||||||
|
@ -120,7 +122,9 @@ public abstract class RFC2617Scheme implements AuthScheme {
|
||||||
if (!s.equalsIgnoreCase(getSchemeName())) {
|
if (!s.equalsIgnoreCase(getSchemeName())) {
|
||||||
throw new MalformedChallengeException("Invalid scheme identifier: " + s);
|
throw new MalformedChallengeException("Invalid scheme identifier: " + s);
|
||||||
}
|
}
|
||||||
HeaderElement[] elements = BasicHeaderValueParser.DEFAULT.parseElements(buffer, pos, buffer.length());
|
HeaderValueParser parser = BasicHeaderValueParser.DEFAULT;
|
||||||
|
ParserCursor cursor = new ParserCursor(pos, buffer.length());
|
||||||
|
HeaderElement[] elements = parser.parseElements(buffer, cursor);
|
||||||
if (elements.length == 0) {
|
if (elements.length == 0) {
|
||||||
throw new MalformedChallengeException("Authentication challenge is empty");
|
throw new MalformedChallengeException("Authentication challenge is empty");
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@ import org.apache.http.conn.params.ConnConnectionPNames;
|
||||||
import org.apache.http.impl.io.AbstractMessageParser;
|
import org.apache.http.impl.io.AbstractMessageParser;
|
||||||
import org.apache.http.io.SessionInputBuffer;
|
import org.apache.http.io.SessionInputBuffer;
|
||||||
import org.apache.http.message.LineParser;
|
import org.apache.http.message.LineParser;
|
||||||
|
import org.apache.http.message.ParserCursor;
|
||||||
import org.apache.http.params.HttpParams;
|
import org.apache.http.params.HttpParams;
|
||||||
import org.apache.http.util.CharArrayBuffer;
|
import org.apache.http.util.CharArrayBuffer;
|
||||||
|
|
||||||
|
@ -75,13 +76,15 @@ public class DefaultResponseParser extends AbstractMessageParser {
|
||||||
this.lineBuf.clear();
|
this.lineBuf.clear();
|
||||||
//read out the HTTP status string
|
//read out the HTTP status string
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
ParserCursor cursor = null;
|
||||||
do {
|
do {
|
||||||
int i = sessionBuffer.readLine(this.lineBuf);
|
int i = sessionBuffer.readLine(this.lineBuf);
|
||||||
if (i == -1 && count == 0) {
|
if (i == -1 && count == 0) {
|
||||||
// The server just dropped connection on us
|
// The server just dropped connection on us
|
||||||
throw new NoHttpResponseException("The target server failed to respond");
|
throw new NoHttpResponseException("The target server failed to respond");
|
||||||
}
|
}
|
||||||
if (lineParser.hasProtocolVersion(this.lineBuf, 0)) {
|
cursor = new ParserCursor(0, this.lineBuf.length());
|
||||||
|
if (lineParser.hasProtocolVersion(this.lineBuf, cursor)) {
|
||||||
// Got one
|
// Got one
|
||||||
break;
|
break;
|
||||||
} else if (i == -1 || count >= this.maxGarbageLines) {
|
} else if (i == -1 || count >= this.maxGarbageLines) {
|
||||||
|
@ -92,7 +95,7 @@ public class DefaultResponseParser extends AbstractMessageParser {
|
||||||
count++;
|
count++;
|
||||||
} while(true);
|
} while(true);
|
||||||
//create the status line from the status string
|
//create the status line from the status string
|
||||||
StatusLine statusline = lineParser.parseStatusLine(this.lineBuf, 0, this.lineBuf.length());
|
StatusLine statusline = lineParser.parseStatusLine(this.lineBuf, cursor);
|
||||||
return this.responseFactory.newHttpResponse(statusline, null);
|
return this.responseFactory.newHttpResponse(statusline, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
|
|
||||||
package org.apache.http.impl.cookie;
|
package org.apache.http.impl.cookie;
|
||||||
|
|
||||||
|
import org.apache.http.FormattedHeader;
|
||||||
import org.apache.http.Header;
|
import org.apache.http.Header;
|
||||||
import org.apache.http.HeaderElement;
|
import org.apache.http.HeaderElement;
|
||||||
import org.apache.http.cookie.ClientCookie;
|
import org.apache.http.cookie.ClientCookie;
|
||||||
|
@ -38,8 +39,8 @@ import org.apache.http.cookie.Cookie;
|
||||||
import org.apache.http.cookie.CookieOrigin;
|
import org.apache.http.cookie.CookieOrigin;
|
||||||
import org.apache.http.cookie.MalformedCookieException;
|
import org.apache.http.cookie.MalformedCookieException;
|
||||||
import org.apache.http.cookie.SM;
|
import org.apache.http.cookie.SM;
|
||||||
import org.apache.http.message.BasicHeaderValueParser;
|
|
||||||
import org.apache.http.message.BufferedHeader;
|
import org.apache.http.message.BufferedHeader;
|
||||||
|
import org.apache.http.message.ParserCursor;
|
||||||
import org.apache.http.util.CharArrayBuffer;
|
import org.apache.http.util.CharArrayBuffer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -121,7 +122,24 @@ public class BrowserCompatSpec extends CookieSpecBase {
|
||||||
}
|
}
|
||||||
HeaderElement[] elems = null;
|
HeaderElement[] elems = null;
|
||||||
if (isNetscapeCookie) {
|
if (isNetscapeCookie) {
|
||||||
elems = new HeaderElement[] { BasicHeaderValueParser.parseHeaderElement(headervalue, null) };
|
NetscapeDraftHeaderParser parser = NetscapeDraftHeaderParser.DEFAULT;
|
||||||
|
CharArrayBuffer buffer;
|
||||||
|
ParserCursor cursor;
|
||||||
|
if (header instanceof FormattedHeader) {
|
||||||
|
buffer = ((FormattedHeader) header).getBuffer();
|
||||||
|
cursor = new ParserCursor(
|
||||||
|
((FormattedHeader) header).getValuePos(),
|
||||||
|
buffer.length());
|
||||||
|
} else {
|
||||||
|
String s = header.getValue();
|
||||||
|
if (s == null) {
|
||||||
|
throw new MalformedCookieException("Header value is null");
|
||||||
|
}
|
||||||
|
buffer = new CharArrayBuffer(s.length());
|
||||||
|
buffer.append(s);
|
||||||
|
cursor = new ParserCursor(0, buffer.length());
|
||||||
|
}
|
||||||
|
elems = new HeaderElement[] { parser.parseHeader(buffer, cursor) };
|
||||||
} else {
|
} else {
|
||||||
elems = header.getElements();
|
elems = header.getElements();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
/*
|
||||||
|
* $HeadURL$
|
||||||
|
* $Revision$
|
||||||
|
* $Date$
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*
|
||||||
|
* This software consists of voluntary contributions made by many
|
||||||
|
* individuals on behalf of the Apache Software Foundation. For more
|
||||||
|
* information on the Apache Software Foundation, please see
|
||||||
|
* <http://www.apache.org/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.apache.http.impl.cookie;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.http.HeaderElement;
|
||||||
|
import org.apache.http.NameValuePair;
|
||||||
|
import org.apache.http.ParseException;
|
||||||
|
import org.apache.http.message.BasicHeaderElement;
|
||||||
|
import org.apache.http.message.BasicHeaderValueParser;
|
||||||
|
import org.apache.http.message.ParserCursor;
|
||||||
|
import org.apache.http.util.CharArrayBuffer;
|
||||||
|
|
||||||
|
public class NetscapeDraftHeaderParser {
|
||||||
|
|
||||||
|
public final static NetscapeDraftHeaderParser DEFAULT = new NetscapeDraftHeaderParser();
|
||||||
|
|
||||||
|
private final static char[] DELIMITERS = new char[] { ';' };
|
||||||
|
|
||||||
|
private final BasicHeaderValueParser nvpParser;
|
||||||
|
|
||||||
|
public NetscapeDraftHeaderParser() {
|
||||||
|
super();
|
||||||
|
this.nvpParser = BasicHeaderValueParser.DEFAULT;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HeaderElement parseHeader(
|
||||||
|
final CharArrayBuffer buffer,
|
||||||
|
final ParserCursor cursor) throws ParseException {
|
||||||
|
if (buffer == null) {
|
||||||
|
throw new IllegalArgumentException("Char array buffer may not be null");
|
||||||
|
}
|
||||||
|
if (cursor == null) {
|
||||||
|
throw new IllegalArgumentException("Parser cursor may not be null");
|
||||||
|
}
|
||||||
|
NameValuePair nvp = this.nvpParser.parseNameValuePair(buffer, cursor, DELIMITERS);
|
||||||
|
List params = new ArrayList();
|
||||||
|
while (!cursor.atEnd()) {
|
||||||
|
NameValuePair param = this.nvpParser.parseNameValuePair(buffer, cursor, DELIMITERS);
|
||||||
|
params.add(param);
|
||||||
|
}
|
||||||
|
return new BasicHeaderElement(
|
||||||
|
nvp.getName(),
|
||||||
|
nvp.getValue(), (NameValuePair[]) params.toArray(new NameValuePair[params.size()]));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -31,6 +31,7 @@
|
||||||
|
|
||||||
package org.apache.http.impl.cookie;
|
package org.apache.http.impl.cookie;
|
||||||
|
|
||||||
|
import org.apache.http.FormattedHeader;
|
||||||
import org.apache.http.Header;
|
import org.apache.http.Header;
|
||||||
import org.apache.http.HeaderElement;
|
import org.apache.http.HeaderElement;
|
||||||
import org.apache.http.cookie.ClientCookie;
|
import org.apache.http.cookie.ClientCookie;
|
||||||
|
@ -38,8 +39,8 @@ import org.apache.http.cookie.Cookie;
|
||||||
import org.apache.http.cookie.CookieOrigin;
|
import org.apache.http.cookie.CookieOrigin;
|
||||||
import org.apache.http.cookie.MalformedCookieException;
|
import org.apache.http.cookie.MalformedCookieException;
|
||||||
import org.apache.http.cookie.SM;
|
import org.apache.http.cookie.SM;
|
||||||
import org.apache.http.message.BasicHeaderValueParser;
|
|
||||||
import org.apache.http.message.BufferedHeader;
|
import org.apache.http.message.BufferedHeader;
|
||||||
|
import org.apache.http.message.ParserCursor;
|
||||||
import org.apache.http.util.CharArrayBuffer;
|
import org.apache.http.util.CharArrayBuffer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -105,8 +106,24 @@ public class NetscapeDraftSpec extends CookieSpecBase {
|
||||||
if (origin == null) {
|
if (origin == null) {
|
||||||
throw new IllegalArgumentException("Cookie origin may not be null");
|
throw new IllegalArgumentException("Cookie origin may not be null");
|
||||||
}
|
}
|
||||||
String headervalue = header.getValue();
|
NetscapeDraftHeaderParser parser = NetscapeDraftHeaderParser.DEFAULT;
|
||||||
return parse(new HeaderElement[] { BasicHeaderValueParser.parseHeaderElement(headervalue, null) }, origin);
|
CharArrayBuffer buffer;
|
||||||
|
ParserCursor cursor;
|
||||||
|
if (header instanceof FormattedHeader) {
|
||||||
|
buffer = ((FormattedHeader) header).getBuffer();
|
||||||
|
cursor = new ParserCursor(
|
||||||
|
((FormattedHeader) header).getValuePos(),
|
||||||
|
buffer.length());
|
||||||
|
} else {
|
||||||
|
String s = header.getValue();
|
||||||
|
if (s == null) {
|
||||||
|
throw new MalformedCookieException("Header value is null");
|
||||||
|
}
|
||||||
|
buffer = new CharArrayBuffer(s.length());
|
||||||
|
buffer.append(s);
|
||||||
|
cursor = new ParserCursor(0, buffer.length());
|
||||||
|
}
|
||||||
|
return parse(new HeaderElement[] { parser.parseHeader(buffer, cursor) }, origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Header[] formatCookies(final Cookie[] cookies) {
|
public Header[] formatCookies(final Cookie[] cookies) {
|
||||||
|
|
|
@ -47,6 +47,7 @@ public class TestAllCookieImpl extends TestCase {
|
||||||
suite.addTest(TestBasicCookieAttribHandlers.suite());
|
suite.addTest(TestBasicCookieAttribHandlers.suite());
|
||||||
suite.addTest(TestNetscapeCookieAttribHandlers.suite());
|
suite.addTest(TestNetscapeCookieAttribHandlers.suite());
|
||||||
suite.addTest(TestRFC2109CookieAttribHandlers.suite());
|
suite.addTest(TestRFC2109CookieAttribHandlers.suite());
|
||||||
|
suite.addTest(TestNetscapeDraftHeaderParser.suite());
|
||||||
suite.addTest(TestBrowserCompatSpec.suite());
|
suite.addTest(TestBrowserCompatSpec.suite());
|
||||||
suite.addTest(TestCookieNetscapeDraft.suite());
|
suite.addTest(TestCookieNetscapeDraft.suite());
|
||||||
suite.addTest(TestCookieRFC2109Spec.suite());
|
suite.addTest(TestCookieRFC2109Spec.suite());
|
||||||
|
|
|
@ -0,0 +1,96 @@
|
||||||
|
/*
|
||||||
|
* $HeadURL$
|
||||||
|
* $Revision$
|
||||||
|
* $Date$
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*
|
||||||
|
* This software consists of voluntary contributions made by many
|
||||||
|
* individuals on behalf of the Apache Software Foundation. For more
|
||||||
|
* information on the Apache Software Foundation, please see
|
||||||
|
* <http://www.apache.org/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.apache.http.impl.cookie;
|
||||||
|
|
||||||
|
import org.apache.http.HeaderElement;
|
||||||
|
import org.apache.http.NameValuePair;
|
||||||
|
import org.apache.http.message.ParserCursor;
|
||||||
|
import org.apache.http.util.CharArrayBuffer;
|
||||||
|
|
||||||
|
import junit.framework.Test;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit tests for {@link NetscapeDraftHeaderParser}.
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
|
||||||
|
*/
|
||||||
|
public class TestNetscapeDraftHeaderParser extends TestCase {
|
||||||
|
|
||||||
|
public TestNetscapeDraftHeaderParser(String testName) {
|
||||||
|
super(testName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String args[]) {
|
||||||
|
String[] testCaseName = { TestNetscapeDraftHeaderParser.class.getName() };
|
||||||
|
junit.textui.TestRunner.main(testCaseName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Test suite() {
|
||||||
|
return new TestSuite(TestNetscapeDraftHeaderParser.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testNetscapeCookieParsing() throws Exception {
|
||||||
|
NetscapeDraftHeaderParser parser = NetscapeDraftHeaderParser.DEFAULT;
|
||||||
|
|
||||||
|
String s =
|
||||||
|
"name = value; test; test1 = stuff,with,commas ; test2 = \"stuff; stuff\"; test3=\"stuff";
|
||||||
|
CharArrayBuffer buffer = new CharArrayBuffer(16);
|
||||||
|
buffer.append(s);
|
||||||
|
ParserCursor cursor = new ParserCursor(0, s.length());
|
||||||
|
|
||||||
|
HeaderElement he = parser.parseHeader(buffer, cursor);
|
||||||
|
assertEquals("name", he.getName());
|
||||||
|
assertEquals("value", he.getValue());
|
||||||
|
NameValuePair[] params = he.getParameters();
|
||||||
|
assertEquals("test", params[0].getName());
|
||||||
|
assertEquals(null, params[0].getValue());
|
||||||
|
assertEquals("test1", params[1].getName());
|
||||||
|
assertEquals("stuff,with,commas", params[1].getValue());
|
||||||
|
assertEquals("test2", params[2].getName());
|
||||||
|
assertEquals("stuff; stuff", params[2].getValue());
|
||||||
|
assertEquals("test3", params[3].getName());
|
||||||
|
assertEquals("\"stuff", params[3].getValue());
|
||||||
|
assertEquals(s.length(), cursor.getPos());
|
||||||
|
assertTrue(cursor.atEnd());
|
||||||
|
|
||||||
|
s = " ";
|
||||||
|
buffer = new CharArrayBuffer(16);
|
||||||
|
buffer.append(s);
|
||||||
|
cursor = new ParserCursor(0, s.length());
|
||||||
|
he = parser.parseHeader(buffer, cursor);
|
||||||
|
assertEquals("", he.getName());
|
||||||
|
assertEquals(null, he.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue