Interface MiscDirectives

All Known Subinterfaces:
Directives
All Known Implementing Classes:
Directives$, MiscDirectives$

public interface MiscDirectives
  • Method Summary

    Modifier and Type
    Method
    Description
    Directive<scala.Tuple1<RemoteAddress>>
    Extracts the client's IP from either the X-Forwarded-For, Remote-Address, X-Real-IP header or pekko.http.scaladsl.model.AttributeKeys.remoteAddress attribute (in that order of priority).
    Directive<scala.Tuple1<RemoteAddress>>
    Extracts the client's IP from the pekko.http.scaladsl.model.AttributeKeys.remoteAddress attribute alone, that is the address of the peer of the connection the request arrived on.
    Directive<scala.runtime.BoxedUnit>
    Converts responses with an empty entity into (empty) rejections.
    Directive<scala.runtime.BoxedUnit>
    Rejects if the request entity is non-empty.
    Directive<scala.runtime.BoxedUnit>
    Rejects with a RequestEntityExpectedRejection if the request entity is empty.
    Directive<scala.Tuple1<Language>>
    selectPreferredLanguage(Language first, scala.collection.immutable.Seq<Language> more)
    Inspects the request's Accept-Language header and determines, which of the given language alternatives is preferred by the client.
    Directive<scala.runtime.BoxedUnit>
    validate(scala.Function0<Object> check, String errorMsg)
    Checks the given condition before running its inner route.
    Directive<scala.runtime.BoxedUnit>
    Disables the size limit (configured by pekko.http.parsing.max-content-length by default) checking on the incoming HttpRequest entity.
    Directive<scala.runtime.BoxedUnit>
    withSizeLimit(long maxBytes)
    Fails the stream with pekko.http.scaladsl.model.EntityStreamSizeException if its request entity size exceeds given limit.
  • Method Details

    • validate

      Directive<scala.runtime.BoxedUnit> validate(scala.Function0<Object> check, String errorMsg)
      Checks the given condition before running its inner route. If the condition fails the route is rejected with a ValidationRejection.

      Parameters:
      check - (undocumented)
      errorMsg - (undocumented)
      Returns:
      (undocumented)
    • extractClientIP

      Directive<scala.Tuple1<RemoteAddress>> extractClientIP()
      Extracts the client's IP from either the X-Forwarded-For, Remote-Address, X-Real-IP header or pekko.http.scaladsl.model.AttributeKeys.remoteAddress attribute (in that order of priority).

      Note that the headers are under the control of the client unless a trusted proxy in front of this server overwrites them. Use extractDirectClientIP() where the address must not be chosen by the client, for example for access control or rate limiting.

      Returns:
      (undocumented)
    • extractDirectClientIP

      Directive<scala.Tuple1<RemoteAddress>> extractDirectClientIP()
      Extracts the client's IP from the pekko.http.scaladsl.model.AttributeKeys.remoteAddress attribute alone, that is the address of the peer of the connection the request arrived on. Forwarding headers are ignored, so the address cannot be chosen by the client, but it is the address of the last proxy rather than of the client itself when the request was forwarded.

      Requires the pekko.http.server.remote-address-attribute setting to be on and extracts pekko.http.scaladsl.model.RemoteAddress.Unknown otherwise.

      Returns:
      (undocumented)
      Since:
      2.0.0
    • requestEntityEmpty

      Directive<scala.runtime.BoxedUnit> requestEntityEmpty()
      Rejects if the request entity is non-empty.

      Returns:
      (undocumented)
    • requestEntityPresent

      Directive<scala.runtime.BoxedUnit> requestEntityPresent()
      Rejects with a RequestEntityExpectedRejection if the request entity is empty. Non-empty requests are passed on unchanged to the inner route.

      Returns:
      (undocumented)
    • rejectEmptyResponse

      Directive<scala.runtime.BoxedUnit> rejectEmptyResponse()
      Converts responses with an empty entity into (empty) rejections. This way you can, for example, have the marshalling of a ''None'' option be treated as if the request could not be matched.

      Returns:
      (undocumented)
    • selectPreferredLanguage

      Directive<scala.Tuple1<Language>> selectPreferredLanguage(Language first, scala.collection.immutable.Seq<Language> more)
      Inspects the request's Accept-Language header and determines, which of the given language alternatives is preferred by the client. (See http://tools.ietf.org/html/rfc7231#section-5.3.5 for more details on the negotiation logic.) If there are several best language alternatives that the client has equal preference for (even if this preference is zero!) the order of the arguments is used as a tie breaker (First one wins).

      Parameters:
      first - (undocumented)
      more - (undocumented)
      Returns:
      (undocumented)
    • withSizeLimit

      Directive<scala.runtime.BoxedUnit> withSizeLimit(long maxBytes)
      Fails the stream with pekko.http.scaladsl.model.EntityStreamSizeException if its request entity size exceeds given limit. Limit given as parameter overrides limit configured with pekko.http.parsing.max-content-length.

      Beware that request entity size check is executed when entity is consumed.

      Parameters:
      maxBytes - (undocumented)
      Returns:
      (undocumented)
    • withoutSizeLimit

      Directive<scala.runtime.BoxedUnit> withoutSizeLimit()
      Disables the size limit (configured by pekko.http.parsing.max-content-length by default) checking on the incoming HttpRequest entity. Can be useful when handling arbitrarily large data uploads in specific parts of your routes.

      Returns:
      (undocumented)