Class RejectionUtils
java.lang.Object
com.netflix.netty.common.throttle.RejectionUtils
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
FieldsModifier and TypeFieldDescriptionstatic final io.netty.handler.codec.http.HttpResponseStatus
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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 aRequestRejectedEvent
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 aRequestRejectedEvent
back up the pipeline.
-
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 aRequestRejectedEvent
back up the pipeline.- Parameters:
nfStatus
- the status to use for metric reportingreason
- 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 aRequestRejectedEvent
back up the pipeline.- Parameters:
ctx
- the channel handler processing the requestnfStatus
- the status to use for metric reportingreason
- 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 ExceptionThrottle either by sending rejection response message, or by closing the connection now, or just drop the message. Only call this if ThrottleResult.shouldThrottle() returnedtrue
.- Parameters:
ctx
- the channel handler processing the requestmsg
- the request that is being rejected.rejectionType
- the type of rejectionnfStatus
- the status to use for metric reportingreason
- 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 requestrejectionType
- the type of rejectionnfStatus
- the status to use for metric reportingreason
- 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 requestrejectionType
- the type of rejectionnfStatus
- the status to use for metric reportingreason
- 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
-