TenanciTenanci

Help centerRoutes, headers & scripts

Headers

Add, replace or remove HTTP headers on the responses sent to the browser and on the requests that reach your app, project-wide or per domain.

HTTP headers are instructions that travel with every page. With header rules you can turn on security protections on the customer's domain, hide server details and send extra information to your app, without touching the origin's code.

How it works

Each rule has a Name, a Value and a Direction:

Direction Where it goes Common uses
Response (browser) Responses the edge delivers to the visitor Security (Strict-Transport-Security, X-Frame-Options, Content-Security-Policy), hiding X-Powered-By
Request (origin) Requests the edge sends to your app Tagging the channel, sending a fixed value your app expects
  • A rule replaces any existing header with the same name;
  • An empty value removes the header (e.g. X-Powered-By with no value disappears from the response);
  • request rules aren't sent to extra origins, only to your app.

Creating a header

  1. Open the project and go to the Customization tab;
  2. On the Headers tab, click Add header;
  3. Fill in Name (e.g. X-Frame-Options) and Value (e.g. SAMEORIGIN);
  4. Pick the Direction: Response (browser) or Request (origin);
  5. Click Add header. The rule takes effect within seconds on every domain in the project.

To change it, edit the fields and click Save; to pause it, use the switch; to delete it, the trash icon.

Headers that can't be changed

To avoid breaking connections or allowing spoofing, some names are ignored:

  • Request: Host, Connection, Content-Length, Transfer-Encoding, Upgrade, TE, Trailer, Keep-Alive, Proxy-Authorization, Proxy-Connection, X-Forwarded-For, X-Real-IP;
  • Response: Content-Length, Content-Encoding, Transfer-Encoding, Connection, Keep-Alive, Upgrade, Trailer.

The tenant context headers (X-Tenanci-Tenant and friends) are set by the edge after your rules: neither a rule nor a visitor can forge them.

Limits: the name must be a standard HTTP header name (letters, digits and -, up to 256 characters), the value up to 8 KB, and up to 100 rules per direction.

Project and domain

As with routes, project rules apply to every domain, and a domain can have its own: on the domain's Customization tab, turn on the switch in the Headers card (Own configuration). From then on the domain uses only its own headers. Details in Routes.

Via the API

Same operations as routes, with headers instead of routes: POST /projects/:id/rules/headers, POST /domains/:id/rules/headers, PATCH /rules/headers/:ruleId and DELETE /rules/headers/:ruleId. direction is response (default) or request.

curl -X POST https://api.tenanci.com/v2/projects/prj_8f3k2m/rules/headers \
  -H "Authorization: Bearer tnc_live_xxxxxxxx_xxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{"name":"X-Frame-Options","value":"SAMEORIGIN","direction":"response"}'