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

Added the ability to set totalCountHeader on a specific request #332

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ericglasser
Copy link

The point of this is to be able to set totalCountHeader on specific requests. We have been dealing with larger collections where some of the queries count is not performant, and do not want it to run on.

@Zertz
Copy link
Collaborator

Zertz commented Jun 13, 2017

I'll take a closer look as soon as possible, thanks for your contribution!

@Zertz Zertz added the feature label Jun 13, 2017
@Zertz Zertz self-assigned this Jun 13, 2017
@Zertz
Copy link
Collaborator

Zertz commented Oct 7, 2017

While this solution solves your issue on the surface, a malicious client could simply remove the query parameter, notice the difference in response time and then you're back to square one: vulnerable to DoS. I do like the idea but I think step one would be to add the ability to set the count header per endpoint and then expose a way to set it dynamically on the server, probably somewhere in pre middleware.

@Zertz Zertz removed their assignment Sep 10, 2019
totalCountHeader = options.totalCountHeader;
}

if (totalCountHeader && !req._ermQueryOptions['distinct']) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy has a fix for the issue: Strings must use doublequote.

Suggested change
if (totalCountHeader && !req._ermQueryOptions['distinct']) {
if (totalCountHeader && !req._ermQueryOptions["distinct"]) {

req.erm.result = items
req.erm.statusCode = 200

if (options.totalCountHeader && !req._ermQueryOptions['distinct']) {
if (req.query.totalCountHeader === 'true') {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy has a fix for the issue: Strings must use doublequote.

Suggested change
if (req.query.totalCountHeader === 'true') {
if (req.query.totalCountHeader === "true") {

if (options.totalCountHeader && !req._ermQueryOptions['distinct']) {
if (req.query.totalCountHeader === 'true') {
totalCountHeader = true;
} else if (req.query.totalCountHeader === 'false') {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy has a fix for the issue: Strings must use doublequote.

Suggested change
} else if (req.query.totalCountHeader === 'false') {
} else if (req.query.totalCountHeader === "false") {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants