Default codec
By default, Scramjet uses simple URL encoding:/scramjet/, a URL like https://example.com becomes:
Creating a custom codec
Custom codecs are defined when creating theScramjetController:
The encoder and decoder functions must be inverse operations - what you encode must be decodable back to the original URL.
Common codec implementations
Base64 encoding
Base64 encoding makes URLs more obfuscated:- Basic
- URL-safe
XOR cipher encoding
Add simple obfuscation with an XOR cipher:Plain encoding
For maximum compatibility and debugging, use plain text URLs:Plain encoding requires special web server configuration to handle URLs containing
:// and other special characters.Custom delimiter encoding
Use a custom delimiter instead of URL encoding:Hash fragment handling
Scramjet automatically handles URL hash fragments separately:Using the controller’s encode/decode methods
TheScramjetController provides helper methods for encoding and decoding URLs:
Protocol handling
Scramjet only proxies HTTP and HTTPS URLs. Other protocols are passed through unchanged:Testing your codec
Here’s a test suite for validating your custom codec:Performance considerations
Encoding speed
Encoding speed
The codec functions are called frequently during page loads. Keep them fast:
URL length
URL length
Some codecs increase URL length significantly:Long URLs may cause issues with some servers or browsers.
Error handling
Error handling
Always handle edge cases:
Related guides
Basic setup
Learn how to configure Scramjet
Configuration flags
Explore other configuration options