mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
[pycharm] DataView/PlotsView (fix): Added getMaxRequestsPerMinute in RestService and overridden in PySciRestService to prevent 429 HHTP error. #PY-43687 Fixed
GitOrigin-RevId: 4e61e154062af8dcf0247988080645bf028ea5ee
This commit is contained in:
committed by
intellij-monorepo-bot
parent
62f90e15eb
commit
18fb57465c
@@ -224,6 +224,7 @@ a:org.jetbrains.ide.RestService
|
||||
- pf:getGson():com.google.gson.Gson
|
||||
- sf:getIntParameter(java.lang.String,io.netty.handler.codec.http.QueryStringDecoder):I
|
||||
- sf:getLastFocusedOrOpenedProject():com.intellij.openapi.project.Project
|
||||
- p:getMaxRequestsPerMinute():I
|
||||
- p:getReportErrorsAsPlainText():Z
|
||||
- p:getRequesterId(io.netty.handler.codec.http.QueryStringDecoder,io.netty.handler.codec.http.FullHttpRequest,io.netty.channel.ChannelHandlerContext):java.lang.Object
|
||||
- pa:getServiceName():java.lang.String
|
||||
|
||||
@@ -98,15 +98,7 @@ abstract class RestService : HttpRequestHandler() {
|
||||
|
||||
@JvmStatic
|
||||
fun sendStatus(status: HttpResponseStatus, keepAlive: Boolean, channel: Channel) {
|
||||
val response = DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status)
|
||||
HttpUtil.setContentLength(response, 0)
|
||||
response.addCommonHeaders()
|
||||
response.addNoCache()
|
||||
if (keepAlive) {
|
||||
HttpUtil.setKeepAlive(response, true)
|
||||
}
|
||||
response.headers().set("X-Frame-Options", "Deny")
|
||||
response.send(channel, !keepAlive)
|
||||
responseStatus(status, keepAlive, channel)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@@ -214,6 +206,14 @@ abstract class RestService : HttpRequestHandler() {
|
||||
return method === HttpMethod.GET
|
||||
}
|
||||
|
||||
/**
|
||||
* If the requests per minute counter exceeds this value, the exception [HttpResponseStatus.TOO_MANY_REQUESTS] will be sent.
|
||||
* @return The value of "ide.rest.api.requests.per.minute" Registry key or '30', if the key does not exist.
|
||||
*/
|
||||
protected open fun getMaxRequestsPerMinute(): Int {
|
||||
return Registry.intValue("ide.rest.api.requests.per.minute", 30)
|
||||
}
|
||||
|
||||
override fun process(urlDecoder: QueryStringDecoder, request: FullHttpRequest, context: ChannelHandlerContext): Boolean {
|
||||
try {
|
||||
if (!isHostTrusted(request, urlDecoder)) {
|
||||
@@ -222,7 +222,7 @@ abstract class RestService : HttpRequestHandler() {
|
||||
}
|
||||
|
||||
val counter = abuseCounter.get(getRequesterId(urlDecoder, request, context))!!
|
||||
if (counter.incrementAndGet() > Registry.intValue("ide.rest.api.requests.per.minute", 30)) {
|
||||
if (counter.incrementAndGet() > getMaxRequestsPerMinute()) {
|
||||
HttpResponseStatus.TOO_MANY_REQUESTS.sendError(context.channel(), request)
|
||||
return true
|
||||
}
|
||||
@@ -371,4 +371,4 @@ fun HttpResponseStatus.orInSafeMode(safeStatus: HttpResponseStatus): HttpRespons
|
||||
else {
|
||||
return safeStatus
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user