8000 [pull] main from miniflux:main by pull[bot] · Pull Request #330 · suhaoGe/miniflux · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions internal/reader/fetcher/request_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ func NewRequestBuilder() *RequestBuilder {
}
}

// Clone returns an independent copy of the builder. Mutating the copy (for
// example to disable redirects for a single request) leaves the original
// untouched.
func (r *RequestBuilder) Clone() *RequestBuilder {
clone := *r
clone.headers = r.headers.Clone()
return &clone
}

func (r *RequestBuilder) WithHeader(key, value string) *RequestBuilder {
r.headers.Set(key, value)
return r
Expand Down
23 changes: 23 additions & 0 deletions internal/reader/fetcher/request_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,29 @@ func TestRequestBuilder_WithoutRedirects(t *testing.T) {
}
}

func TestRequestBuilder_Clone(t *testing.T) {
original := NewRequestBuilder().WithHeader("X-Shared", "value")

clone := original.Clone().WithoutRedirects()
clone.WithHeader("X-Clone-Only", "value")

if original.withoutRedirects {
t.Error("Mutating the clone should not disable redirects on the original")
}

if original.headers.Get("X-Clone-Only") != "" {
t.Error("Mutating the clone's headers should not affect the original")
}

if clone.headers.Get("X-Shared") != "value" {
t.Error("Expected the clone to inherit the original headers")
}

if clone.clientTimeout != original.clientTimeout {
t.Error("Expected the clone to inherit the original timeout")
}
}

func TestRequestBuilder_DisableHTTP2(t *testing.T) {
builder := NewRequestBuilder()
builder = builder.DisableHTTP2(true)
Expand Down
5 changes: 4 additions & 1 deletion internal/reader/subscription/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,10 @@ func (f *subscriptionFinder) findSubscriptionsFromWellKnownURLs(websiteURL strin
// Some websites redirects unknown URLs to the home page.
// As result, the list of known URLs is returned to the subscription list.
// We don't want the user to choose between invalid feed URLs.
requestBuilder := f.requestBuilder.WithoutRedirects()
//
// Probe each known URL on its own builder so disabling redirects
// here doesn't leak into the finder's other requests.
requestBuilder := f.requestBuilder.Clone().WithoutRedirects()

responseHandler := fetcher.NewResponseHandler(requestBuilder.ExecuteRequest(fullURL))
localizedError := responseHandler.LocalizedError()
Expand Down
0