diff --git a/java/google/registry/proxy/handler/QuotaHandler.java b/java/google/registry/proxy/handler/QuotaHandler.java index 7c2c2071d..1381d72c9 100644 --- a/java/google/registry/proxy/handler/QuotaHandler.java +++ b/java/google/registry/proxy/handler/QuotaHandler.java @@ -79,10 +79,7 @@ public abstract class QuotaHandler extends ChannelInboundHandlerAdapter { static class OverQuotaException extends Exception { OverQuotaException(String protocol, String userId) { - super( - String.format( - "\nPROTOCOL: %s\nUSER ID: %s\nQuota exceeded, terminating connection.", - protocol, userId)); + super(String.format("Quota exceeded for: PROTOCOL: %s, USER ID: %s", protocol, userId)); } } diff --git a/java/google/registry/proxy/handler/RelayHandler.java b/java/google/registry/proxy/handler/RelayHandler.java index 5f3afc2af..dc4e7862c 100644 --- a/java/google/registry/proxy/handler/RelayHandler.java +++ b/java/google/registry/proxy/handler/RelayHandler.java @@ -17,6 +17,7 @@ package google.registry.proxy.handler; import static google.registry.proxy.Protocol.PROTOCOL_KEY; import com.google.common.flogger.FluentLogger; +import google.registry.proxy.handler.QuotaHandler.OverQuotaException; import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelHandlerContext; @@ -70,6 +71,17 @@ public class RelayHandler extends SimpleChannelInboundHandler { } } + @Override + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { + if (cause instanceof OverQuotaException) { + logger.atWarning().withCause(cause).log( + "Channel %s closed due to quota exceeded", ctx.channel()); + ChannelFuture unusedFuture = ctx.close(); + } else { + ctx.fireExceptionCaught(cause); + } + } + public static void writeToRelayChannel( Channel channel, Channel relayChannel, Object msg, boolean retry) { ChannelFuture unusedFuture = diff --git a/java/google/registry/proxy/handler/WebWhoisRedirectHandler.java b/java/google/registry/proxy/handler/WebWhoisRedirectHandler.java index e7bacb3ad..9ab57b86e 100644 --- a/java/google/registry/proxy/handler/WebWhoisRedirectHandler.java +++ b/java/google/registry/proxy/handler/WebWhoisRedirectHandler.java @@ -22,6 +22,7 @@ import static io.netty.handler.codec.http.HttpHeaderNames.LOCATION; import static io.netty.handler.codec.http.HttpHeaderValues.KEEP_ALIVE; import static io.netty.handler.codec.http.HttpHeaderValues.TEXT_PLAIN; import static io.netty.handler.codec.http.HttpMethod.GET; +import static io.netty.handler.codec.http.HttpMethod.HEAD; import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST; import static io.netty.handler.codec.http.HttpResponseStatus.FORBIDDEN; import static io.netty.handler.codec.http.HttpResponseStatus.FOUND; @@ -32,6 +33,7 @@ import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1; import com.google.common.base.Splitter; import com.google.common.base.Strings; +import com.google.common.collect.ImmutableList; import com.google.common.flogger.FluentLogger; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; @@ -39,6 +41,7 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.handler.codec.http.DefaultFullHttpResponse; import io.netty.handler.codec.http.FullHttpResponse; +import io.netty.handler.codec.http.HttpMethod; import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.HttpUtil; import java.time.Duration; @@ -75,6 +78,7 @@ public class WebWhoisRedirectHandler extends SimpleChannelInboundHandler ALLOWED_METHODS = ImmutableList.of(GET, HEAD); private final boolean isHttps; private final String redirectHost; @@ -87,8 +91,7 @@ public class WebWhoisRedirectHandler extends SimpleChannelInboundHandler