=htp Extract RemoteAddress.Unknown when cannot find client ip (#21289)
* handle unknown client ip * updated doc * fixed java dsl test
This commit is contained in:
parent
3e86c2a44f
commit
0e302d2236
4 changed files with 9 additions and 3 deletions
|
|
@ -11,7 +11,7 @@ Signature
|
|||
|
||||
Description
|
||||
-----------
|
||||
Provides the value of ``X-Forwarded-For``, ``Remote-Address``, or ``X-Real-IP`` headers as an instance of ``HttpIp``.
|
||||
Provides the value of ``X-Forwarded-For``, ``Remote-Address``, or ``X-Real-IP`` headers as an instance of ``RemoteAddress``.
|
||||
|
||||
The akka-http server engine adds the ``Remote-Address`` header to every request automatically if the respective
|
||||
setting ``akka.http.server.remote-address-header`` is set to ``on``. Per default it is set to ``off``.
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ public class MiscDirectivesTest extends JUnitRouteTest {
|
|||
|
||||
route
|
||||
.run(HttpRequest.create())
|
||||
.assertStatusCode(StatusCodes.NOT_FOUND);
|
||||
.assertStatusCode(StatusCodes.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -30,6 +30,11 @@ class MiscDirectivesSpec extends RoutingSpec {
|
|||
extractClientIP { echoComplete }
|
||||
} ~> check { responseAs[String] shouldEqual "1.2.3.4" }
|
||||
}
|
||||
"extract unknown when no headers" in {
|
||||
Get() ~> {
|
||||
extractClientIP { echoComplete }
|
||||
} ~> check { responseAs[String] shouldEqual "unknown" }
|
||||
}
|
||||
}
|
||||
|
||||
"the selectPreferredLanguage directive" should {
|
||||
|
|
|
|||
|
|
@ -104,7 +104,8 @@ object MiscDirectives extends MiscDirectives {
|
|||
private val _extractClientIP: Directive1[RemoteAddress] =
|
||||
headerValuePF { case `X-Forwarded-For`(Seq(address, _*)) ⇒ address } |
|
||||
headerValuePF { case `Remote-Address`(address) ⇒ address } |
|
||||
headerValuePF { case `X-Real-Ip`(address) ⇒ address }
|
||||
headerValuePF { case `X-Real-Ip`(address) ⇒ address } |
|
||||
extract[RemoteAddress] { case _ ⇒ RemoteAddress.Unknown }
|
||||
|
||||
private val _requestEntityEmpty: Directive0 =
|
||||
extract(_.request.entity.isKnownEmpty).flatMap(if (_) pass else reject)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue