Repository navigation
Add custom HTTP header support - #17
Closed
infraguard-web wants to merge 1 commit into
Closed
infraguard-web wants to merge 1 commit into
infraguard-web wants to merge 1 commit into
Conversation
infraguard-web
force-pushed
the
fix/custom-headers-rebased
branch
from
May 1, 2026 15:09
00add70 to
aed3ec4
Compare
There was a problem hiding this comment.
Pull request overview
Adds global, repeatable --header CLI support so custom HTTP headers can be configured once and applied across outbound HTTP clients/transports (including detectors and the HuggingFace source).
Changes:
- Introduce a global, atomically stored
feature.CustomHeadersand parse--headerflags into it at startup. - Apply globally configured headers in shared HTTP transports (common transport + detector transport).
- Route HuggingFace HTTP client through the common instrumented/custom transport and update docs/manpage for the new flag.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/sources/huggingface/client.go | Switch HF client to use common instrumented + custom transport so global headers are applied. |
| pkg/feature/feature.go | Add CustomHeaders global and AtomicHeader helper for atomic storage. |
| pkg/detectors/readme/readme.go | Use the shared detector HTTP client (so transport-level behavior like custom headers applies). |
| pkg/detectors/http.go | Apply global custom headers in detector transport RoundTrip. |
| pkg/common/http.go | Add ApplyCustomHeaders and apply it in CustomTransport.RoundTrip. |
| main.go | Add repeatable --header flag and parse/store headers globally. |
| docs/man/trufflehog.1 | Document the new --header flag and expected formats. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+52
to
+62
| // Load returns the current http.Header value; may be nil if unset. | ||
| func (ah *AtomicHeader) Load() http.Header { | ||
| if v := ah.value.Load(); v != nil { | ||
| return v.(http.Header) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // Store sets the http.Header value. | ||
| func (ah *AtomicHeader) Store(h http.Header) { | ||
| ah.value.Store(h) |
Comment on lines
+99
to
113
| // ApplyCustomHeaders adds any globally configured custom headers to req. | ||
| func ApplyCustomHeaders(req *http.Request) { | ||
| if hdr := feature.CustomHeaders.Load(); hdr != nil { | ||
| for k, vals := range hdr { | ||
| for _, v := range vals { | ||
| req.Header.Add(k, v) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func (t *CustomTransport) RoundTrip(req *http.Request) (*http.Response, error) { | ||
| req.Header.Add("User-Agent", UserAgent()) | ||
| ApplyCustomHeaders(req) | ||
| return t.T.RoundTrip(req) |
Comment on lines
76
to
80
| func (t *detectorTransport) RoundTrip(req *http.Request) (*http.Response, error) { | ||
| req.Header.Add("User-Agent", userAgent()) | ||
| common.ApplyCustomHeaders(req) | ||
| return t.T.RoundTrip(req) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Verification