Skip to content
This repository has been archived by the owner on May 12, 2020. It is now read-only.

Commit

Permalink
Add an explicitcancel option
Browse files Browse the repository at this point in the history
  • Loading branch information
bbondy committed Mar 16, 2019
1 parent 74b167c commit d9377e2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 4 additions & 2 deletions filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ void Filter::parseOption(const char *input, int len) {
*pFilterOption = static_cast<FilterOption>(*pFilterOption | FOWebsocket);
} else if (!strncmp(pStart, "important", len)) {
*pFilterOption = static_cast<FilterOption>(*pFilterOption | FOImportant);
} else if (!strncmp(pStart, "explicitcancel", len)) {
*pFilterOption = static_cast<FilterOption>(*pFilterOption | FOExplicitCancel);
} else {
*pFilterOption = static_cast<FilterOption>(*pFilterOption | FOUnknown);
std::string option(pStart, len);
Expand Down Expand Up @@ -445,12 +447,12 @@ bool Filter::matchesOptions(const char *input, FilterOption context,
// blocking a the HTTP level, don't block here because we don't have enough
// information
if (context != FONoFilterOption) {
if ((filterOption & ~FOThirdParty) != FONoFilterOption
if ((filterOption & ~BehavioralFilterOnly) != FONoFilterOption
&& !(filterOption & FOResourcesOnly & context)) {
return false;
}

if ((antiFilterOption & ~FOThirdParty) != FONoFilterOption
if ((antiFilterOption & ~BehavioralFilterOnly) != FONoFilterOption
&& (antiFilterOption & FOResourcesOnly & context)) {
return false;
}
Expand Down
7 changes: 5 additions & 2 deletions filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#ifndef FILTER_H_
#define FILTER_H_

#include <stdint.h>
#include <string.h>
#include "./base.h"
Expand Down Expand Up @@ -72,14 +71,18 @@ enum FilterOption {
FOWebsocket = 0200000000,
// important means to ignore all exception filters (those prefixed with @@).
FOImportant = 0400000000,
// Cancel the request instead of using a 200 OK response
FOExplicitCancel = 01000000000,

FOUnknown = 04000000000,
FOResourcesOnly = FOScript|FOImage|FOStylesheet|FOObject|FOXmlHttpRequest|
FOObjectSubrequest|FOSubdocument|FODocument|FOOther|FOXBL|FOFont|FOMedia|
FOWebRTC|FOWebsocket|FOPing,
FOUnsupportedSoSkipCheck = FOPopup|FOCSP|FOElemHide|FOGenericHide|
FOGenericBlock|FOEmpty|FOUnknown,
FOUnsupportedButIgnore = FORedirect|FOImportant
// Non matching related filters, alters behavior
BehavioralFilterOnly = FORedirect|FOImportant|FOExplicitCancel|
FOThirdParty|FONotThirdParty
};

class Filter {
Expand Down

0 comments on commit d9377e2

Please sign in to comment.