All Projects → echocat → caddy-filter

echocat / caddy-filter

Licence: other
Provides a directive to filter response bodies in caddy.

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to caddy-filter

Caddy Authz
Caddy-authz is a middleware for Caddy that blocks or allows requests based on access control policies.
Stars: ✭ 221 (+513.89%)
Mutual labels:  filter, caddy
leaflet-tag-filter-button
Adds tag filter control for layers (marker, geojson features etc.) to LeafLet.
Stars: ✭ 48 (+33.33%)
Mutual labels:  filter
FilteredIntent
Android intent filter library
Stars: ✭ 35 (-2.78%)
Mutual labels:  filter
sql-repository
[PHP 7] SQL Repository implementation
Stars: ✭ 37 (+2.78%)
Mutual labels:  filter
caddy-crowdsec-bouncer
A Caddy module that blocks malicious traffic based on decisions made by CrowdSec.
Stars: ✭ 40 (+11.11%)
Mutual labels:  caddy
AdvancedHTMLParser
Fast Indexed python HTML parser which builds a DOM node tree, providing common getElementsBy* functions for scraping, testing, modification, and formatting. Also XPath.
Stars: ✭ 90 (+150%)
Mutual labels:  filter
object.omit
Return a copy of an object without the given keys.
Stars: ✭ 79 (+119.44%)
Mutual labels:  filter
cargo-limit
Cargo with less noise: warnings are skipped until errors are fixed, Neovim integration, etc.
Stars: ✭ 105 (+191.67%)
Mutual labels:  filter
adam
Addon which enhances all user profiles of confluence. It also adds an advanced people directory. The whole addon is configurable by means of an XML, can be localized, supports Velocity templates and supports view and edit restrictions.
Stars: ✭ 12 (-66.67%)
Mutual labels:  echocat
ASH-IR-Dataset
An impulse response dataset for binaural synthesis of spatial audio systems on headphones
Stars: ✭ 100 (+177.78%)
Mutual labels:  filter
liqe
Lightweight and performant Lucene-like parser, serializer and search engine.
Stars: ✭ 513 (+1325%)
Mutual labels:  filter
piii.js
A filter for bad words (in Portuguese).
Stars: ✭ 122 (+238.89%)
Mutual labels:  filter
MyAfterEffects
A complete video editor
Stars: ✭ 28 (-22.22%)
Mutual labels:  filter
caddy-altonions
Opportunistic Onions plugin for Caddy
Stars: ✭ 20 (-44.44%)
Mutual labels:  caddy
coraza-caddy
OWASP Coraza middleware for Caddy. It provides Web Application Firewall capabilities
Stars: ✭ 75 (+108.33%)
Mutual labels:  caddy
ember-cli-blog
Tom Dale's blog example updated for the Ember CLI
Stars: ✭ 87 (+141.67%)
Mutual labels:  filter
regXwild
⏱ Superfast ^Advanced wildcards++? | Unique algorithms that was implemented on native unmanaged C++ but easily accessible in .NET via Conari (with caching of 0x29 opcodes +optimizations) etc.
Stars: ✭ 20 (-44.44%)
Mutual labels:  filter
vidlist
Command line program to subscribe to youtube channels and view link/thumbnail in a locally generated html page
Stars: ✭ 31 (-13.89%)
Mutual labels:  html-page
TD-Flow-ABS
Real-time Flow-based Image and Video Abstraction in TouchDesigner.
Stars: ✭ 72 (+100%)
Mutual labels:  filter
Silverdog
An audio firewall for Chrome!
Stars: ✭ 65 (+80.56%)
Mutual labels:  filter

Go Report Card Build Status Coverage Status License

caddy-filter

filter allows you to modify the responses.

This could be useful to modify static HTML files to add (for example) Google Analytics source code to it.

Syntax

filter rule {
    path                          <regexp pattern>
    content_type                  <regexp pattern>
    path_content_type_combination <and|or>
    search_pattern                <regexp pattern>
    replacement                   <replacement pattern>
}
filter rule ...
filter max_buffer_size    <maximum buffer size in bytes>
  • rule: Defines a new filter rule for a file to respond.

    Important: Define path and/or content_type not to open. Slack rules could dramatically impact the system performance because every response is recorded to memory before returning it.

    • path: Regular expression that matches the requested path.
    • content_type: Regular expression that matches the requested content type that results after the evaluation of the whole request.
    • path_content_type_combination: (Since 0.8) Could be and or or. (Default: and - before this parameter existed it was or)
    • search_pattern: Regular expression to find in the response body to replace it.
    • replacement: Pattern to replace the search_pattern with.
      You can use parameters. Each parameter must be formatted like: {name}.
      • Regex group: Every group of the search_pattern could be addressed with {index}.
        Example: "My name is (.*?) (.*?)." => "Name: {2}, {1}."

      • Request context: Parameters like URL ... could be accessed.
        Example: Host: {request_host}

        • request_header_<header name>: Contains a header value of the request, if provided or empty.
        • request_url: Full requested url
        • request_path: Requested path
        • request_method: Used method
        • request_host: Target host
        • request_proto: Used proto
        • request_remoteAddress: Remote address of the calling client
        • response_header_<header name>: Contains a header value of the response, if provided or empty.
        • env_<environment variable name>: Contains an environment variable value, if provided or empty.
        • now[:<pattern>]: Current timestamp. If pattern not provided, RFC or RFC3339 RFC3339 is used. Other values: unix, timestamp or free format following Golang time formatting rules.
        • response_header_last_modified[:<pattern>]: Same like now for last modification time of current resource - see above. If not send by server current time will be used.
      • Replacements in files: If the replacement is prefixed with a @ character it will be tried to find a file with this name and load the replacement from there. This will help you to also add replacements with larger payloads which will be ugly direct within the Caddyfile.
        Example: @myfile.html

  • max_buffer_size: Limit the buffer size to the specified maximum number of bytes. If a rules matches the whole body will be recorded at first to memory before delivery to HTTP client. If this limit is reached no filtering will executed and the content is directly forwarded to the client to prevent memory overload. Default is: 10485760 (=10 MB)

Examples

Replace in every text file Foo with Bar.

filter rule {
    path .*\.txt
    search_pattern Foo
    replacement Bar
}

Add Google Analytics to every HTML page from a file.

Caddyfile:

filter rule {
    path .*\.html
    search_pattern </title>
    replacement @header.html
}

header.html:

<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create', 'UA-12345678-9', 'auto');ga('send', 'pageview');</script>
</title>

Insert server name in every HTML page

filter rule {
    content_type text/html.*
    search_pattern Server
    replacement "This site was provided by {response_header_Server}"
}

Run tests

Full

This includes download of all dependencies and also creation and upload of coverage reports.

No working golang installation is required but Java 8+ (in PATH or JAVA_HOME set.).

# On Linux/macOS
$ ./gradlew test

# On Windows
$ gradlew test

Native

Requires a working golang installation in PATH and GOPATH set.

$ go test

Contributing

caddy-filter is an open source project by echocat. So if you want to make this project even better, you can contribute to this project on Github by fork us.

If you commit code to this project, you have to accept that this code will be released under the license of this project.

License

See the LICENSE file.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].