-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a config option to limit request body size (#276)
- Loading branch information
1 parent
537eee6
commit 68b248a
Showing
7 changed files
with
189 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...e/src/main/java/org/apache/polaris/service/throttling/RequestThrottlingErrorResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.polaris.service.throttling; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
/** | ||
* Response object for errors caused by DoS-prevention throttling mechanisms, such as request size | ||
* limits | ||
*/ | ||
public class RequestThrottlingErrorResponse { | ||
public enum RequestThrottlingErrorType { | ||
REQUEST_TOO_LARGE, | ||
; | ||
} | ||
|
||
private final RequestThrottlingErrorType errorType; | ||
|
||
@JsonCreator | ||
public RequestThrottlingErrorResponse( | ||
@JsonProperty("error_type") RequestThrottlingErrorType errorType) { | ||
this.errorType = errorType; | ||
} | ||
|
||
public RequestThrottlingErrorType getErrorType() { | ||
return errorType; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...main/java/org/apache/polaris/service/throttling/StreamReadConstraintsExceptionMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.polaris.service.throttling; | ||
|
||
import com.fasterxml.jackson.core.exc.StreamConstraintsException; | ||
import jakarta.ws.rs.core.MediaType; | ||
import jakarta.ws.rs.core.Response; | ||
import jakarta.ws.rs.ext.ExceptionMapper; | ||
|
||
/** | ||
* Handles exceptions during the request that are a result of stream constraints such as the request | ||
* being too large | ||
*/ | ||
public class StreamReadConstraintsExceptionMapper | ||
implements ExceptionMapper<StreamConstraintsException> { | ||
|
||
@Override | ||
public Response toResponse(StreamConstraintsException exception) { | ||
return Response.status(Response.Status.BAD_REQUEST) | ||
.type(MediaType.APPLICATION_JSON_TYPE) | ||
.entity( | ||
new RequestThrottlingErrorResponse( | ||
RequestThrottlingErrorResponse.RequestThrottlingErrorType.REQUEST_TOO_LARGE)) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters