diff options
| author | bptato <nincsnevem662@gmail.com> | 2024-11-03 17:21:52 +0100 |
|---|---|---|
| committer | bptato <nincsnevem662@gmail.com> | 2024-11-03 17:21:52 +0100 |
| commit | cfc6bb4c3cb773b035fa54de2aa90efbdd47216e (patch) | |
| tree | 8695e2d7654a3a145929465d688a273481efb047 /src/io | |
| parent | 21186a3f41bb0328dd34007d2f6300101e75a7cb (diff) | |
| download | chawan-cfc6bb4c3cb773b035fa54de2aa90efbdd47216e.tar.gz | |
utils, types: merge some modules
* line, vector, matrix -> path
* twtuni, charcategory -> twtstr
Diffstat (limited to 'src/io')
| -rw-r--r-- | src/io/urlfilter.nim | 44 |
1 files changed, 0 insertions, 44 deletions
diff --git a/src/io/urlfilter.nim b/src/io/urlfilter.nim deleted file mode 100644 index 20983498..00000000 --- a/src/io/urlfilter.nim +++ /dev/null @@ -1,44 +0,0 @@ -import std/options - -import monoucha/jsregex -import types/url - -#TODO add denyhost/s for blocklists -type URLFilter* = object - scheme: Option[string] - allowschemes*: seq[string] - allowhost*: Option[string] - allowhosts: seq[Regex] - default: bool - -proc newURLFilter*(scheme = none(string); allowschemes: seq[string] = @[]; - allowhost = none(string); allowhosts: seq[Regex] = @[]; - default = false): URLFilter = - doAssert scheme.isSome or allowschemes.len == 0, - "allowschemes without scheme is not supported" - return URLFilter( - scheme: scheme, - allowschemes: allowschemes, - allowhost: allowhost, - allowhosts: allowhosts, - default: default - ) - -# Filters as follows: -# If scheme/s are given, only URLs with the same scheme are matched. -# Then, allowhost and allowhosts are checked; if none of these match the host, -# the function returns the value of `default'. -proc match*(filter: URLFilter; url: URL): bool = - block check_scheme: - if filter.scheme.isSome and filter.scheme.get != url.scheme: - for scheme in filter.allowschemes: - if scheme == url.scheme: - break check_scheme - return false - let host = url.host - if filter.allowhost.isSome and filter.allowhost.get == host: - return true - for regex in filter.allowhosts: - if regex.match(host): - return true - return filter.default |