From 57613ba547e1e61ece1fd6cf903e2872cc66660f Mon Sep 17 00:00:00 2001 From: June Kelly Date: Tue, 14 Dec 2021 10:14:57 +0000 Subject: [PATCH] Merge pull request #6063 from overleaf/jk-gitbridge-rate-limit-429 [git-bridge] Pass 429 and message to client GitOrigin-RevId: f751b27efdbad9d775dead2a209fd7468c253ad2 --- .../ic/wlgitbridge/server/Oauth2Filter.java | 46 +++++++++++-------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/server/Oauth2Filter.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/server/Oauth2Filter.java index bbf2696cd3..8bed1e6efb 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/server/Oauth2Filter.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/server/Oauth2Filter.java @@ -220,26 +220,34 @@ public class Oauth2Filter implements Filter { HttpServletResponse response = servletResponse; response.setContentType("text/plain"); response.setHeader("WWW-Authenticate", "Basic realm=\"Git Bridge\""); - response.setStatus(401); - PrintWriter w = response.getWriter(); - w.println( - "Please sign in using your email address and Overleaf password." - ); - w.println(); - w.println( - "*Note*: if you sign in to Overleaf using another provider, " - + "such " - ); - w.println( - "as Google or Twitter, you need to set a password " - + "on your Overleaf " - ); - w.println( - "account first. " - + "Please see https://www.overleaf.com/blog/195 for " - ); - w.println("more information."); + if (statusCode == 429) { + // Rate limit + response.setStatus(429); + w.println( + "Rate limit exceeded. Please wait and try again later." + ); + } else { + response.setStatus(401); + w.println( + "Please sign in using your email address and Overleaf password." + ); + w.println(); + w.println( + "*Note*: if you sign in to Overleaf using another provider, " + + "such " + ); + w.println( + "as Google or Twitter, you need to set a password " + + "on your Overleaf " + ); + w.println( + "account first. " + + "Please see https://www.overleaf.com/blog/195 for " + ); + w.println("more information."); + } + w.close(); }