Skip to content

Conversation

absar0920
Copy link

@absar0920 absar0920 commented Aug 18, 2025

Custom HTTP Header Management

This PR adds the ability to add, modify, and remove HTTP headers when forwarding requests to origin services through Cloudflare Tunnel.

Works with

  • CLI Flags: --header and --remove-header for quick tunnel setups
  • Configuration Files: Support for headers in YAML/JSON config files

add the feature request: #1499

Usage

CLI Flags (Quick Tunnels)

cloudflared tunnel --url http://localhost:3000 \
  --header "X-API-Key: your-api-key" \ # custom headers
  --header "Authorization: Bearer 123456789" \
  --header "X-Service-Name: my-service"

cloudflared tunnel --url http://localhost:3000 \
  --remove-header "User-Agent" \ # remove headers from the request
  --remove-header "Server"

Configuration Files

tunnel: your-tunnel-name
credentials-file: /path/to/credentials.json

ingress:
  - hostname: "*.example.com"
    service: http://localhost:8000
    originRequest:
      headers:
        X-API-Key: "your-api-key"
        Authorization: "Bearer 123456789"
        X-Service-Name: "my-service"
      removeHeaders:
        - "User-Agent"
        - "Server"
  - service: http_status:404

Testing

I have added test cases for the changes

MISC

This is a optional change, and it does not break the exisiting functionallity. It is fully backward compatible.

I have also attached screenshots by creating tunnels with a simple nodejs server as a receiver.

Command
image

Server logs before using the remove headers flag
image

Server logs after using the remove headers flag
image

yaml config usage
image

test cases
image

@absar0920
Copy link
Author

this pr is for a feature request. Here is the issue link: #1499

@absar0920
Copy link
Author

@DevinCarr Can I get a review for this pr. Thanks.
This is my first pr in the project.

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

Successfully merging this pull request may close these issues.

1 participant