Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2016-02-04 06:00:13 +0000
committerGreg Wilkins2016-02-04 06:00:13 +0000
commitdf79ad689a38592472d3696e15bf0252e617b8e7 (patch)
treec2fedd48685d4f06c044821f01b3a7c12a455b71 /jetty-http
parent459ba4ae5aa7f9a29d18b4e08848ff6e1cec0e4a (diff)
parent009fde2400a746b1ce24ba04bd4fcd001378516b (diff)
downloadorg.eclipse.jetty.project-df79ad689a38592472d3696e15bf0252e617b8e7.tar.gz
org.eclipse.jetty.project-df79ad689a38592472d3696e15bf0252e617b8e7.tar.xz
org.eclipse.jetty.project-df79ad689a38592472d3696e15bf0252e617b8e7.zip
Merge remote-tracking branch 'origin/jetty-9.3.x'
Diffstat (limited to 'jetty-http')
-rw-r--r--jetty-http/src/main/java/org/eclipse/jetty/http/HttpURI.java19
-rw-r--r--jetty-http/src/test/java/org/eclipse/jetty/http/HttpURITest.java10
2 files changed, 28 insertions, 1 deletions
diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpURI.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpURI.java
index f0e271117b..6b0a39a2d6 100644
--- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpURI.java
+++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpURI.java
@@ -334,6 +334,8 @@ public class HttpURI
state=State.PORT;
break;
case '@':
+ if (_user!=null)
+ throw new IllegalArgumentException("Bad authority");
_user=uri.substring(mark,i);
mark=i+1;
break;
@@ -372,7 +374,16 @@ public class HttpURI
case PORT:
{
- if (c=='/')
+ if (c=='@')
+ {
+ if (_user!=null)
+ throw new IllegalArgumentException("Bad authority");
+ // It wasn't a port, but a password!
+ _user=_host+":"+uri.substring(mark,i);
+ mark=i+1;
+ state=State.HOST;
+ }
+ else if (c=='/')
{
_port=TypeUtil.parseInt(uri,mark,i-mark,10);
path_mark=mark=i;
@@ -745,6 +756,12 @@ public class HttpURI
return _host+":"+_port;
return _host;
}
+
+ /* ------------------------------------------------------------ */
+ public String getUser()
+ {
+ return _user;
+ }
}
diff --git a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpURITest.java b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpURITest.java
index d308cde3b5..74c6feedde 100644
--- a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpURITest.java
+++ b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpURITest.java
@@ -22,6 +22,7 @@ package org.eclipse.jetty.http;
import static org.junit.Assert.*;
import java.io.UnsupportedEncodingException;
+import java.net.URI;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
@@ -193,4 +194,13 @@ public class HttpURITest
assertEquals("http:/path/info",uri.toString());
}
+
+ @Test
+ public void testBasicAuthCredentials() throws Exception
+ {
+ HttpURI uri = new HttpURI("http://user:password@example.com:8888/blah");
+ assertEquals("http://user:password@example.com:8888/blah", uri.toString());
+ assertEquals(uri.getAuthority(), "example.com:8888");
+ assertEquals(uri.getUser(), "user:password");
+ }
}

Back to the top