Class RejectionUtils

java.lang.Object
com.netflix.netty.common.throttle.RejectionUtils

public final class RejectionUtils extends Object
A collection of rejection related utilities useful for failing requests. These are tightly coupled with the channel pipeline, but can be called from different handlers.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final io.netty.handler.codec.http.HttpResponseStatus
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    allowThenClose(io.netty.channel.ChannelHandlerContext ctx)
    Marks the given channel for being closed after the next response.
    static void
    handleRejection(io.netty.channel.ChannelHandlerContext ctx, Object msg, RejectionType rejectionType, StatusCategory nfStatus, String reason, Integer injectedLatencyMillis, io.netty.handler.codec.http.HttpResponseStatus rejectedCode, String rejectedBody, Map<String,String> rejectionHeaders)
    Throttle either by sending rejection response message, or by closing the connection now, or just drop the message.
    static void
    reject(io.netty.channel.ChannelHandlerContext ctx, RejectionType rejectionType, StatusCategory nfStatus, String reason, io.netty.handler.codec.http.HttpRequest request, Integer injectedLatencyMillis, io.netty.handler.codec.http.HttpResponseStatus rejectedCode, String rejectedBody)
    Switches on the rejection type to decide how to reject the request and or close the conn.
    static void
    reject(io.netty.channel.ChannelHandlerContext ctx, RejectionType rejectionType, StatusCategory nfStatus, String reason, io.netty.handler.codec.http.HttpRequest request, Integer injectedLatencyMillis, io.netty.handler.codec.http.HttpResponseStatus rejectedCode, String rejectedBody, Map<String,String> rejectionHeaders)
    Switches on the rejection type to decide how to reject the request and or close the conn.
    static void
    rejectByClosingConnection(io.netty.channel.ChannelHandlerContext ctx, StatusCategory nfStatus, String reason, io.netty.handler.codec.http.HttpRequest request, Integer injectedLatencyMillis)
    Closes the connection without sending a response, and fires a RequestRejectedEvent back up the pipeline.
    static void
    sendRejectionResponse(io.netty.channel.ChannelHandlerContext ctx, StatusCategory nfStatus, String reason, io.netty.handler.codec.http.HttpRequest request, Integer injectedLatencyMillis, io.netty.handler.codec.http.HttpResponseStatus rejectedCode, String rejectedBody, Map<String,String> rejectionHeaders)
    Sends a rejection response back to the client, and fires a RequestRejectedEvent back up the pipeline.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • REJECT_CLOSING_STATUS

      public static final io.netty.handler.codec.http.HttpResponseStatus REJECT_CLOSING_STATUS
  • Method Details

    • rejectByClosingConnection

      public static void rejectByClosingConnection(io.netty.channel.ChannelHandlerContext ctx, StatusCategory nfStatus, String reason, io.netty.handler.codec.http.HttpRequest request, @Nullable Integer injectedLatencyMillis)
      Closes the connection without sending a response, and fires a RequestRejectedEvent back up the pipeline.
      Parameters:
      nfStatus - the status to use for metric reporting
      reason - the reason for rejecting the request. This is not sent back to the client.
      request - the request that is being rejected.
      injectedLatencyMillis - optional parameter to delay sending a response. The reject notification is still sent up the pipeline.
    • sendRejectionResponse

      public static void sendRejectionResponse(io.netty.channel.ChannelHandlerContext ctx, StatusCategory nfStatus, String reason, io.netty.handler.codec.http.HttpRequest request, @Nullable Integer injectedLatencyMillis, io.netty.handler.codec.http.HttpResponseStatus rejectedCode, String rejectedBody, Map<String,String> rejectionHeaders)
      Sends a rejection response back to the client, and fires a RequestRejectedEvent back up the pipeline.
      Parameters:
      ctx - the channel handler processing the request
      nfStatus - the status to use for metric reporting
      reason - the reason for rejecting the request. This is not sent back to the client.
      request - the request that is being rejected.
      injectedLatencyMillis - optional parameter to delay sending a response. The reject notification is still sent up the pipeline.
      rejectedCode - the HTTP code to send back to the client.
      rejectedBody - the HTTP body to be sent back. It is assumed to be of type text/plain.
      rejectionHeaders - additional HTTP headers to add to the rejection response
    • allowThenClose

      public static void allowThenClose(io.netty.channel.ChannelHandlerContext ctx)
      Marks the given channel for being closed after the next response.
      Parameters:
      ctx - the channel handler processing the request
    • handleRejection

      public static void handleRejection(io.netty.channel.ChannelHandlerContext ctx, Object msg, RejectionType rejectionType, StatusCategory nfStatus, String reason, @Nullable Integer injectedLatencyMillis, io.netty.handler.codec.http.HttpResponseStatus rejectedCode, String rejectedBody, Map<String,String> rejectionHeaders) throws Exception
      Throttle either by sending rejection response message, or by closing the connection now, or just drop the message. Only call this if ThrottleResult.shouldThrottle() returned true.
      Parameters:
      ctx - the channel handler processing the request
      msg - the request that is being rejected.
      rejectionType - the type of rejection
      nfStatus - the status to use for metric reporting
      reason - the reason for rejecting the request. This is not sent back to the client.
      injectedLatencyMillis - optional parameter to delay sending a response. The reject notification is still sent up the pipeline.
      rejectedCode - the HTTP code to send back to the client.
      rejectedBody - the HTTP body to be sent back. It is assumed to be of type text/plain.
      rejectionHeaders - additional HTTP headers to add to the rejection response
      Throws:
      Exception
    • reject

      public static void reject(io.netty.channel.ChannelHandlerContext ctx, RejectionType rejectionType, StatusCategory nfStatus, String reason, io.netty.handler.codec.http.HttpRequest request, @Nullable Integer injectedLatencyMillis, io.netty.handler.codec.http.HttpResponseStatus rejectedCode, String rejectedBody)
      Switches on the rejection type to decide how to reject the request and or close the conn.
      Parameters:
      ctx - the channel handler processing the request
      rejectionType - the type of rejection
      nfStatus - the status to use for metric reporting
      reason - the reason for rejecting the request. This is not sent back to the client.
      request - the request that is being rejected.
      injectedLatencyMillis - optional parameter to delay sending a response. The reject notification is still sent up the pipeline.
      rejectedCode - the HTTP code to send back to the client.
      rejectedBody - the HTTP body to be sent back. It is assumed to be of type text/plain.
    • reject

      public static void reject(io.netty.channel.ChannelHandlerContext ctx, RejectionType rejectionType, StatusCategory nfStatus, String reason, io.netty.handler.codec.http.HttpRequest request, @Nullable Integer injectedLatencyMillis, io.netty.handler.codec.http.HttpResponseStatus rejectedCode, String rejectedBody, Map<String,String> rejectionHeaders)
      Switches on the rejection type to decide how to reject the request and or close the conn.
      Parameters:
      ctx - the channel handler processing the request
      rejectionType - the type of rejection
      nfStatus - the status to use for metric reporting
      reason - the reason for rejecting the request. This is not sent back to the client.
      request - the request that is being rejected.
      injectedLatencyMillis - optional parameter to delay sending a response. The reject notification is still sent up the pipeline.
      rejectedCode - the HTTP code to send back to the client.
      rejectedBody - the HTTP body to be sent back. It is assumed to be of type text/plain.
      rejectionHeaders - additional HTTP headers to add to the rejection response