HSTS header in Nginx - Time & Space Complexity
We want to understand how adding the HSTS header affects nginx's work as requests come in.
Specifically, how does the server's effort change as more requests arrive?
Analyze the time complexity of the following nginx configuration snippet.
server {
listen 443 ssl;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
# other config...
}
This snippet adds the HSTS header to every HTTPS response to tell browsers to use HTTPS only.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Adding the HSTS header to each HTTPS response.
- How many times: Once per HTTPS request received by the server.
Each new HTTPS request causes nginx to add the HSTS header once.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 header additions |
| 100 | 100 header additions |
| 1000 | 1000 header additions |
Pattern observation: The work grows directly with the number of requests.
Time Complexity: O(n)
This means the server's work to add the HSTS header grows linearly with the number of HTTPS requests.
[X] Wrong: "Adding the HSTS header slows down the server exponentially as requests increase."
[OK] Correct: Adding a header is a simple step done once per request, so the work grows steadily, not exponentially.
Understanding how simple configuration changes affect server work helps you explain performance impacts clearly and confidently.
"What if we added multiple headers instead of just one? How would the time complexity change?"