Skip to content

Further improve readability and maintainability of middleware/secure.go #2799

Description

@suwakei

Improved readability of HSTS header construction logic

Currently, the logic for constructing the value of the Strict-Transport-Security (HSTS) header is to nest fmt.Sprintf and concatenate the strings.
I believe that rewriting this part by adding each directive (max-age, includeSubdomains, preload) to the slice and finally joining them with strings.Join will make the logic clearer and improve readability.

Add comment regarding X-XSS-Protection header

The X-XSS-Protection header is deprecated in many modern browsers, and the Content-Security-Policy (CSP) header is recommended.
While this header is important for backward compatibility, I believe that supplementing this background with comments will help users of this middleware choose more appropriate security settings.

Activity

  1. suwakei commented on Jul 4, 2025

    @suwakei
    ContributorAuthor

    Target PR: #2800

  2. added a commit that references this issue on Sep 16, 2025
    a9df64c
  3. vishr commented on Jun 13, 2026

    @vishr
    Member

    Closing as a cosmetic/style suggestion with no functional change — a small PR refactoring the HSTS string building is welcome if you'd like to pursue it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions