Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
thythm
ribbon
提交
195fb203
R
ribbon
项目概览
thythm
/
ribbon
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
ribbon
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
195fb203
编写于
4月 14, 2014
作者:
A
Allen Wang
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of
https://github.com/Netflix/ribbon
into cp
上级
7d799471
42c3e4ca
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
32 addition
and
30 deletion
+32
-30
ribbon-core/src/main/java/com/netflix/client/LoadBalancerContext.java
...src/main/java/com/netflix/client/LoadBalancerContext.java
+15
-30
ribbon-core/src/test/java/com/netflix/client/LoadBalancerContextTest.java
...test/java/com/netflix/client/LoadBalancerContextTest.java
+17
-0
未找到文件。
ribbon-core/src/main/java/com/netflix/client/LoadBalancerContext.java
浏览文件 @
195fb203
...
...
@@ -394,7 +394,6 @@ public abstract class LoadBalancerContext<T extends ClientRequest, S extends IRe
*/
@SuppressWarnings
(
"unchecked"
)
protected
T
computeFinalUriWithLoadBalancer
(
T
original
)
throws
ClientException
{
URI
newURI
;
URI
theUrl
=
original
.
getUri
();
if
(
theUrl
==
null
){
...
...
@@ -514,42 +513,28 @@ public abstract class LoadBalancerContext<T extends ClientRequest, S extends IRe
// just verify that at this point we have a full URL
try
{
String
urlPath
=
""
;
if
(
theUrl
.
getRawPath
()
!=
null
&&
theUrl
.
getRawPath
().
startsWith
(
"/"
))
{
urlPath
=
theUrl
.
getRawPath
();
}
else
{
urlPath
=
"/"
+
theUrl
.
getRawPath
();
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
scheme
).
append
(
"://"
);
if
(!
Strings
.
isNullOrEmpty
(
theUrl
.
getRawUserInfo
()))
{
sb
.
append
(
theUrl
.
getRawUserInfo
()).
append
(
"@"
);
}
newURI
=
new
URI
(
scheme
,
theUrl
.
getUserInfo
(),
host
,
port
,
urlPath
,
theUrl
.
getQuery
(),
theUrl
.
getFragment
());
if
(
isURIEncoded
(
theUrl
))
{
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
newURI
.
getScheme
())
.
append
(
"://"
)
.
append
(
newURI
.
getRawAuthority
())
.
append
(
theUrl
.
getRawPath
());
if
(!
Strings
.
isNullOrEmpty
(
theUrl
.
getRawQuery
()))
{
sb
.
append
(
"?"
).
append
(
theUrl
.
getRawQuery
());
}
if
(!
Strings
.
isNullOrEmpty
(
theUrl
.
getRawFragment
()))
{
sb
.
append
(
"#"
).
append
(
theUrl
.
getRawFragment
());
}
newURI
=
new
URI
(
sb
.
toString
());
sb
.
append
(
host
);
if
(
port
>=
0
)
{
sb
.
append
(
":"
).
append
(
port
);
}
sb
.
append
(
theUrl
.
getRawPath
());
if
(!
Strings
.
isNullOrEmpty
(
theUrl
.
getRawQuery
()))
{
sb
.
append
(
"?"
).
append
(
theUrl
.
getRawQuery
());
}
if
(!
Strings
.
isNullOrEmpty
(
theUrl
.
getRawFragment
()))
{
sb
.
append
(
"#"
).
append
(
theUrl
.
getRawFragment
());
}
URI
newURI
=
new
URI
(
sb
.
toString
());
return
(
T
)
original
.
replaceUri
(
newURI
);
}
catch
(
URISyntaxException
e
)
{
throw
new
ClientException
(
ClientException
.
ErrorType
.
GENERAL
,
e
.
getMessage
());
}
}
private
boolean
isURIEncoded
(
URI
uri
)
{
String
original
=
uri
.
toString
();
try
{
return
!
URLEncoder
.
encode
(
original
,
"UTF-8"
).
equals
(
original
);
}
catch
(
Exception
e
)
{
return
false
;
}
}
protected
boolean
isRetriable
(
T
request
)
{
if
(
request
.
isRetriable
())
{
...
...
ribbon-core/src/test/java/com/netflix/client/LoadBalancerContextTest.java
浏览文件 @
195fb203
...
...
@@ -61,6 +61,23 @@ public class LoadBalancerContextTest {
assertEquals
(
uri
,
newRequest
.
getUri
().
toString
());
}
@Test
public
void
testPreservesUserInfo
()
throws
ClientException
{
// %3A == ":" -- ensure user info is not decoded
String
uri
=
"http://us%3Aer:pass@localhost:8080?foo=bar"
;
HttpRequest
request
=
HttpRequest
.
newBuilder
().
uri
(
uri
).
build
();
HttpRequest
newRequest
=
context
.
computeFinalUriWithLoadBalancer
(
request
);
assertEquals
(
uri
,
newRequest
.
getUri
().
toString
());
}
@Test
public
void
testQueryWithoutPath
()
throws
ClientException
{
String
uri
=
"?foo=bar"
;
HttpRequest
request
=
HttpRequest
.
newBuilder
().
uri
(
uri
).
build
();
HttpRequest
newRequest
=
context
.
computeFinalUriWithLoadBalancer
(
request
);
assertEquals
(
"http://www.example.com:8080?foo=bar"
,
newRequest
.
getUri
().
toString
());
}
@Test
public
void
testEncodedPathAndHostChange
()
throws
ClientException
{
String
uri
=
"/abc%2Fxyz"
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录