Skip to content

Commit

Permalink
use explict structs for report-only values
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobbednarz committed Nov 12, 2022
1 parent b730cf1 commit 0f5b85a
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,38 @@ func main() {
r := mux.NewRouter()
r.HandleFunc(*healthCheckPath, handler.HealthcheckHandler).Methods("GET")

cspHandler := &handler.CSPViolationReportHandler{
r.Handle("/csp/report-only", &handler.CSPViolationReportHandler{
BlockedURIs: ignoredBlockedURIs,
TruncateQueryStringFragment: *truncateQueryStringFragment,

LogClientIP: *logClientIP,
LogTruncatedClientIP: *logTruncatedClientIP,
MetadataObject: *metadataObject,
Logger: logger,
}
ReportOnly: true,
}).Methods("POST")

r.Handle("/csp", &handler.CSPViolationReportHandler{
BlockedURIs: ignoredBlockedURIs,
TruncateQueryStringFragment: *truncateQueryStringFragment,

reportOnlyCspHandler := cspHandler
reportOnlyCspHandler.ReportOnly = true
LogClientIP: *logClientIP,
LogTruncatedClientIP: *logTruncatedClientIP,
MetadataObject: *metadataObject,
Logger: logger,
ReportOnly: false,
}).Methods("POST")

r.Handle("/csp", cspHandler).Methods("POST")
r.Handle("/csp/report-only", reportOnlyCspHandler).Methods("POST")
r.Handle("/", cspHandler).Methods("POST")
r.Handle("/", &handler.CSPViolationReportHandler{
BlockedURIs: ignoredBlockedURIs,
TruncateQueryStringFragment: *truncateQueryStringFragment,

LogClientIP: *logClientIP,
LogTruncatedClientIP: *logTruncatedClientIP,
MetadataObject: *metadataObject,
Logger: logger,
ReportOnly: false,
}).Methods("POST")

r.NotFoundHandler = r.NewRoute().HandlerFunc(http.NotFound).GetHandler()

Expand Down

0 comments on commit 0f5b85a

Please sign in to comment.