HTTPCLIENT-813: Fixed default port resolution. Invalid ports no longer get replaced with the default port value.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@744520 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2009-02-14 16:46:33 +00:00
parent eb29d0e8ce
commit dd5061b2ab
3 changed files with 69 additions and 1 deletions

View File

@ -9,6 +9,10 @@ bundle combining HttpClient and HttpMime jars.
All upstream projects are strongly encouraged to upgrade. All upstream projects are strongly encouraged to upgrade.
* [HTTPCLIENT-813] Fixed default port resolution. Invalid ports no longer
get replaced with the default port value.
Contributed by Oleg Kalnichevski <olegk at apache.org>
* Fixed NPE in DefaultRequestDirector thrown when retrying a failed * Fixed NPE in DefaultRequestDirector thrown when retrying a failed
request over a proxied connection. request over a proxied connection.
Contributed by Oleg Kalnichevski <olegk at apache.org> Contributed by Oleg Kalnichevski <olegk at apache.org>

View File

@ -161,7 +161,7 @@ public final class Scheme {
* @return the given port or the defaultPort * @return the given port or the defaultPort
*/ */
public final int resolvePort(int port) { public final int resolvePort(int port) {
return ((port <= 0) || (port > 0xffff)) ? defaultPort : port; return port <= 0 ? defaultPort : port;
} }

View File

@ -0,0 +1,64 @@
/*
* $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.conn.scheme;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Unit tests for {@link Scheme}.
*/
public class TestScheme extends TestCase {
public TestScheme(String testName) {
super(testName);
}
public static void main(String args[]) {
String[] testCaseName = { TestScheme.class.getName() };
junit.textui.TestRunner.main(testCaseName);
}
public static Test suite() {
return new TestSuite(TestScheme.class);
}
public void testPortResolution() {
Scheme http = new Scheme("http", PlainSocketFactory.getSocketFactory(), 80);
assertEquals(80, http.resolvePort(0));
assertEquals(80, http.resolvePort(-1));
assertEquals(8080, http.resolvePort(8080));
assertEquals(80808080, http.resolvePort(80808080));
}
}