Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate Remote-Address header #3174

Merged
merged 3 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
/**
* Model for the `Remote-Address` header.
* Custom header we use for optionally transporting the peer's IP in an HTTP header.
*
* Deprecated since 10.2.0: use the remote-header-attribute instead.
*/
@Deprecated
public abstract class RemoteAddress extends akka.http.scaladsl.model.HttpHeader {
public abstract akka.http.javadsl.model.RemoteAddress address();

Expand Down
1 change: 1 addition & 0 deletions akka-http-core/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ akka.http {

# Enables/disables the addition of a `Remote-Address` header
# holding the clients (remote) IP address.
# Deprecated since 10.2.0: please use `remote-address-attribute` instead.
remote-address-header = off

# Enables/disables the addition of a remote-address attribute in HttpRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import akka.http.scaladsl.model.headers.`Timeout-Access`
import akka.http.javadsl.model
import akka.http.scaladsl.model._
import akka.http.impl.util.LogByteStringTools._
import com.github.ghik.silencer.silent

import scala.util.Failure

Expand Down Expand Up @@ -125,6 +126,7 @@ private[http] object HttpServerBluePrint {
case RequestStart(method, uri, protocol, hdrs, entityCreator, _, _) =>
val effectiveMethod = if (method == HttpMethods.HEAD && settings.transparentHeadRequests) HttpMethods.GET else method

@silent("use remote-address-attribute instead")
val effectiveHeaders =
if (settings.remoteAddressHeader && remoteAddressOpt.isDefined)
headers.`Remote-Address`(RemoteAddress(remoteAddressOpt.get)) +: hdrs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ import scala.concurrent.duration.{ Duration, FiniteDuration }
def getTimeouts: ServerSettings.Timeouts
def getMaxConnections: Int
def getPipeliningLimit: Int

/**
* Deprecated since 10.2.0, use remoteAddressAttribute instead
*/
@Deprecated
def getRemoteAddressHeader: Boolean
def getRemoteAddressAttribute: Boolean
def getRawRequestUriHeader: Boolean
Expand Down
2 changes: 2 additions & 0 deletions akka-http-core/src/main/scala/akka/http/scaladsl/Http.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import akka.stream.TLSProtocol._
import akka.stream.scaladsl._
import akka.util.ByteString
import akka.util.ManifestInfo
import com.github.ghik.silencer.silent
import com.typesafe.config.Config
import com.typesafe.sslconfig.akka._
import com.typesafe.sslconfig.akka.util.AkkaLoggerFactory
Expand Down Expand Up @@ -1030,6 +1031,7 @@ object Http extends ExtensionId[HttpExt] with ExtensionIdProvider {
def createExtension(system: ExtendedActorSystem): HttpExt =
new HttpExt(system.settings.config getConfig "akka.http")(system)

@silent("use remote-address-attribute instead")
@InternalApi
private[akka] def prepareAttributes(settings: ServerSettings, incoming: Tcp.IncomingConnection) =
if (settings.remoteAddressHeader || settings.remoteAddressAttribute) HttpAttributes.remoteAddress(incoming.remoteAddress)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,9 @@ final case class `Raw-Request-URI`(uri: String) extends jm.headers.RawRequestURI
protected def companion = `Raw-Request-URI`
}

@deprecated("use remote-address-attribute instead", since = "10.2.0")
object `Remote-Address` extends ModeledCompanion[`Remote-Address`]
@deprecated("use remote-address-attribute instead", since = "10.2.0")
final case class `Remote-Address`(address: RemoteAddress) extends jm.headers.RemoteAddress with SyntheticHeader {
def renderValue[R <: Rendering](r: R): r.type = r ~~ address
protected def companion = `Remote-Address`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ abstract class ServerSettings private[akka] () extends akka.http.javadsl.setting
def timeouts: ServerSettings.Timeouts
def maxConnections: Int
def pipeliningLimit: Int
@deprecated("use remote-address-attribute instead", since = "10.2.0")
def remoteAddressHeader: Boolean
def remoteAddressAttribute: Boolean
def rawRequestUriHeader: Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ import akka.http.scaladsl.model._
import akka.testkit._
import headers._
import java.net.InetAddress

import akka.http.scaladsl.server.util.VarArgsFunction1
import com.github.ghik.silencer.silent

@silent("use remote-address-attribute instead")
class MiscDirectivesSpec extends RoutingSpec {

"the extractClientIP directive" should {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import akka.http.scaladsl.settings.ServerSettings
import akka.stream.Attributes
import akka.stream.scaladsl.Source
import akka.util.ByteString
import com.github.ghik.silencer.silent

import scala.annotation.tailrec
import scala.collection.immutable.VectorBuilder
Expand All @@ -27,6 +28,7 @@ import scala.collection.immutable.VectorBuilder
@InternalApi
private[http2] object RequestParsing {

@silent("use remote-address-attribute instead")
def parseRequest(httpHeaderParser: HttpHeaderParser, serverSettings: ServerSettings, attributes: Attributes): Http2SubStream => HttpRequest = {
val remoteAddressHeader: Option[`Remote-Address`] =
if (serverSettings.remoteAddressHeader) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@

import akka.http.javadsl.model.HttpRequest;
import akka.http.javadsl.model.StatusCodes;
import akka.http.javadsl.model.headers.AcceptLanguage;
import akka.http.javadsl.model.headers.Language;
import akka.http.javadsl.model.headers.LanguageRanges;
import akka.http.javadsl.model.headers.RemoteAddress;
import akka.http.javadsl.model.headers.*;
import akka.http.javadsl.server.PathMatchers;
import akka.http.javadsl.server.Route;
import akka.http.javadsl.testkit.JUnitRouteTest;
Expand Down Expand Up @@ -150,11 +147,11 @@ public void testExtractClientIP() throws UnknownHostException {

// tests:
final String ip = "192.168.1.2";
final akka.http.javadsl.model.RemoteAddress remoteAddress =
final akka.http.javadsl.model.RemoteAddress remoteAddress =
akka.http.javadsl.model.RemoteAddress.create(InetAddress.getByName(ip));

final HttpRequest request = HttpRequest.GET("/")
.addHeader(RemoteAddress.create(remoteAddress)); //
.addHeader(XForwardedFor.create(remoteAddress)); //

testRoute(route).run(request)
.assertEntity("Client's IP is " + ip);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class MiscDirectivesExamplesSpec extends RoutingSpec with CompileOnlySpec {
}

// tests:
Get("/").withHeaders(`Remote-Address`(RemoteAddress(InetAddress.getByName("192.168.3.12")))) ~> route ~> check {
Get("/").withHeaders(`X-Forwarded-For`(RemoteAddress(InetAddress.getByName("192.168.3.12")))) ~> route ~> check {
responseAs[String] shouldEqual "Client's ip is 192.168.3.12"
}
//#extractClientIP-example
Expand Down