Skip to content

Add support for custom HTTP headers in tile requests #383

@loaiz1982

Description

@loaiz1982

Feature Description

Use Case:
I'm serving PMTiles with TOTP-based authentication for security. Currently, I'm passing the token as a URL query parameter (?token=123456), but this
is suboptimal because:

  1. Security: Tokens appear in logs, browser history, and cache keys
  2. Caching: Each token rotation creates new cache entries, reducing cache efficiency
  3. Best Practice: Authentication tokens should be sent via headers (e.g., Authorization or X-Map-Token)

Requested Feature:
Add support for custom HTTP headers when fetching tiles from tile sources (PMTiles, raster, vector). This would allow:

  MapLibreMap(
    styleString: styleJson,
    tileRequestHeaders: {
      'X-Map-Token': totpToken,
      'Authorization': 'Bearer $token',
    },
  )

Benefits:

  • Tokens excluded from URLs (better security, cleaner logs)
  • Improved cache efficiency (cache key based on URL, not token)
  • Follows HTTP authentication best practices
  • Enables proper CDN caching with authenticated tiles

Current Workaround:
Using query parameters (/tiles.pmtiles?token=123456), which works but has the limitations mentioned above.

Sample Use Case

  MapLibreMap(
    styleString: styleJson,
    tileRequestHeaders: {
      'X-Map-Token': totpToken,
      'Authorization': 'Bearer $token',
    },
  )

Existing Alternatives or Workarounds

Using query parameters (/tiles.pmtiles?token=123456), which works but has the limitations mentioned above.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or request

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions