Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
apollo
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
apollo
Commits
1fe24756
Commit
1fe24756
authored
Aug 23, 2016
by
张乐
Committed by
GitHub
Aug 23, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #387 from nobodyiam/forwarded-for-list
adapt for list result of X-FORWARDED-FOR
parents
91065c0d
714df8dd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
4 deletions
+7
-4
ConfigController.java
...ork/apollo/configservice/controller/ConfigController.java
+7
-4
No files found.
apollo-configservice/src/main/java/com/ctrip/framework/apollo/configservice/controller/ConfigController.java
View file @
1fe24756
package
com
.
ctrip
.
framework
.
apollo
.
configservice
.
controller
;
package
com
.
ctrip
.
framework
.
apollo
.
configservice
.
controller
;
import
com.google.common.base.Joiner
;
import
com.google.common.base.Joiner
;
import
com.google.common.base.Splitter
;
import
com.google.common.base.Strings
;
import
com.google.common.base.Strings
;
import
com.google.common.collect.FluentIterable
;
import
com.google.common.collect.FluentIterable
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Lists
;
...
@@ -40,6 +41,8 @@ import javax.servlet.http.HttpServletResponse;
...
@@ -40,6 +41,8 @@ import javax.servlet.http.HttpServletResponse;
@RestController
@RestController
@RequestMapping
(
"/configs"
)
@RequestMapping
(
"/configs"
)
public
class
ConfigController
{
public
class
ConfigController
{
private
static
final
Splitter
X_FORWARDED_FOR_SPLITTER
=
Splitter
.
on
(
","
).
omitEmptyStrings
()
.
trimResults
();
@Autowired
@Autowired
private
ReleaseService
releaseService
;
private
ReleaseService
releaseService
;
@Autowired
@Autowired
...
@@ -220,11 +223,11 @@ public class ConfigController {
...
@@ -220,11 +223,11 @@ public class ConfigController {
}
}
private
String
tryToGetClientIp
(
HttpServletRequest
request
)
{
private
String
tryToGetClientIp
(
HttpServletRequest
request
)
{
String
ipAddress
=
request
.
getHeader
(
"X-FORWARDED-FOR"
);
String
forwardedFor
=
request
.
getHeader
(
"X-FORWARDED-FOR"
);
if
(
ipAddress
==
null
)
{
if
(
!
Strings
.
isNullOrEmpty
(
forwardedFor
)
)
{
ipAddress
=
request
.
getRemoteAddr
(
);
return
X_FORWARDED_FOR_SPLITTER
.
splitToList
(
forwardedFor
).
get
(
0
);
}
}
return
ipAddress
;
return
request
.
getRemoteAddr
()
;
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment