Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature-Add default and max pagination limit support to prevent large response errors #278

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions opentaxii/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class ServerConfig(dict):
"title",
"public_discovery",
"allow_custom_properties",
"max_pagination_limit",
"default_pagination_limit"
)
ALL_VALID_OPTIONS = VALID_BASE_OPTIONS + VALID_TAXII_OPTIONS + VALID_TAXII1_OPTIONS

Expand Down
2 changes: 2 additions & 0 deletions opentaxii/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ taxii1:
create_tables: yes

taxii2:
default_pagination_limit: 10
max_pagination_limit: 1000

logging:
opentaxii: info
Expand Down
2 changes: 2 additions & 0 deletions opentaxii/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ def collection_handler(self, api_root_id, collection_id_or_alias):
)
def manifest_handler(self, api_root_id, collection_id_or_alias):
filter_params = validate_list_filter_params(request.args, self.persistence.api)
filter_params["limit"] = self.config.get("max_pagination_limit") if filter_params.get("limit", self.config.get("max_pagination_limit")) > self.config.get("max_pagination_limit") else filter_params.get("limit", self.config.get("default_pagination_limit"))
try:
manifest, more = self.persistence.get_manifest(
api_root_id=api_root_id,
Expand Down Expand Up @@ -652,6 +653,7 @@ def objects_handler(self, api_root_id, collection_id_or_alias):

def objects_get_handler(self, api_root_id, collection_id_or_alias):
filter_params = validate_list_filter_params(request.args, self.persistence.api)
filter_params["limit"] = self.config.get("max_pagination_limit") if filter_params.get("limit", self.config.get("max_pagination_limit")) > self.config.get("max_pagination_limit") else filter_params.get("limit", self.config.get("default_pagination_limit"))
try:
objects, more, next_param = self.persistence.get_objects(
api_root_id=api_root_id,
Expand Down