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

Initial filter implementation #27

Merged
merged 3 commits into from
Apr 19, 2024
Merged

Initial filter implementation #27

merged 3 commits into from
Apr 19, 2024

Conversation

jamesmunns
Copy link
Collaborator

Closes #24.

This introduces basic "Request Path Control" features - the ability to modify or block in-flight requests.

Additionally, this switches to the more complete http proxy facilities provided by pingora.

@jamesmunns
Copy link
Collaborator Author

When making a request:

curl --header "X-MyHeader-secret: 123" -vvvv --insecure https://fedora.local:4443

With this Control Path config:

# "Path Control" affects requests and responses as they are proxied
[basic-proxy.path-control]
# upstream request filters specifically allow for the cancellation or modification
# of requests, as they are being made.
#
# Filters are applied in the order they are specified. Multiple instances of
# each filter may be provided.
upstream-request-filters = [
    # Remove any headers with keys matching `pattern`
    { kind = "remove-header-key-regex", pattern = ".*(secret|SECRET).*" },
    # Add or replace (e.g. "Upsert") a fixed header with the given key and value
    { kind = "upsert-header", key = "x-proxy-friend", value = "river" },
]

We can see the requests being made, and the filter operations occurring:

2024-04-18T14:24:18.598712Z DEBUG pingora_proxy: Successfully get a new request    
2024-04-18T14:24:18.598784Z TRACE pingora_proxy: Request header: Parts { method: GET, uri: /, version: HTTP/1.1, headers: {"host": "fedora.local:4443", "user-agent": "curl/8.4.0", "accept": "*/*", "x-myheader-secret": "123"} }    
2024-04-18T14:24:18.599457Z DEBUG pingora_core::connectors: No reusable connection found for addr: 91.107.223.4:443, scheme: HTTPS,sni: onevariable.com,    
2024-04-18T14:24:18.621248Z DEBUG pingora_core::connectors::l4: connected to new server: 91.107.223.4:443    

!!!

2024-04-18T14:24:18.649995Z DEBUG river::proxy::request_modifiers: Removing header: "x-myheader-secret"
2024-04-18T14:24:18.650187Z DEBUG river::proxy::request_modifiers: Inserted header: x-proxy-friend: river
2024-04-18T14:24:18.650224Z DEBUG pingora_proxy::proxy_h1: Sending header to upstream RequestHeader { base: Parts { method: GET, uri: /, version: HTTP/1.1, headers: {"host": "fedora.local:4443", "user-agent": "curl/8.4.0", "accept": "*/*", "x-proxy-friend": "river"} }, header_name_map: Some({"host": CaseHeaderName(b"Host"), "user-agent": CaseHeaderName(b"User-Agent"), "accept": CaseHeaderName(b"Accept"), "x-proxy-friend": CaseHeaderName(b"x-proxy-friend")}), raw_path_fallback: [] }    

!!!

2024-04-18T14:24:18.650319Z TRACE pingora_core::protocols::http::v1::client: Writing request header: b"GET / HTTP/1.1\r\nHost: fedora.local:4443\r\nUser-Agent: curl/8.4.0\r\nAccept: */*\r\nx-proxy-friend: river\r\n\r\n"    
2024-04-18T14:24:18.650737Z DEBUG pingora_proxy::proxy_h1: finish sending body to upstream

(area highlighted by me with !!! showing the actions taken)

@jamesmunns jamesmunns added the F-RequestPathCtl Functionality relating to the Request Path Control for modification and filtering label Apr 18, 2024
@jamesmunns jamesmunns added this to the Kickstart Spike 1 milestone Apr 18, 2024
@jamesmunns
Copy link
Collaborator Author

Also added the same filters to the Response path as well.

@jamesmunns jamesmunns merged commit 5bfa341 into main Apr 19, 2024
@jamesmunns jamesmunns deleted the james/first-filters branch April 19, 2024 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-RequestPathCtl Functionality relating to the Request Path Control for modification and filtering
Projects
None yet
Development

Successfully merging this pull request may close these issues.

First Request Path Demo
1 participant