Skip to content

Commit 90e3898

Browse files
authored
release: 0.0.4 (#4)
2 parents 2c4e731 + 33dae26 commit 90e3898

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/main/kotlin/org/gitanimals/identity/controller/interceptor/InternalApiInterceptor.kt

+5-6
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ class InternalApiInterceptor(
1414
response: HttpServletResponse,
1515
handler: Any,
1616
): Boolean {
17-
val ip = extractIp(request)
18-
return whiteIps.contains(ip)
17+
return whiteIps.contains(extractIp(request))
1918
}
2019

2120
private fun extractIp(request: HttpServletRequest): String {
@@ -25,22 +24,22 @@ class InternalApiInterceptor(
2524
"X-Real-IP", "X-RealIP", "REMOTE_ADDR"
2625
)
2726

28-
var ip: String = request.getHeader("X-Forwarded-For")
27+
var ip: String? = request.getHeader("X-Forwarded-For")
2928

3029
for (header in headers) {
31-
if (ip.isEmpty() || "unknown".equals(ip, ignoreCase = true)) {
30+
if (ip.isNullOrEmpty() || "unknown".equals(ip, ignoreCase = true)) {
3231
ip = request.getHeader(header)
3332
}
3433
}
3534

36-
if (ip.isEmpty() || "unknown".equals(ip, ignoreCase = true)) {
35+
if (ip.isNullOrEmpty() || "unknown".equals(ip, ignoreCase = true)) {
3736
ip = request.remoteAddr
3837
}
3938

4039
if (ip == "0:0:0:0:0:0:0:1") {
4140
ip = "127.0.0.1"
4241
}
4342

44-
return ip
43+
return ip ?: throw IllegalStateException("Cannot extract ip")
4544
}
4645
}

0 commit comments

Comments
 (0)