Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gen-bundle: Allow multiple entries for single URL #541

Merged
merged 1 commit into from
Dec 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions go/bundle/cmd/gen-bundle/fromhar.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func fromHar(harPath string) ([]*bundle.Exchange, error) {
}

es := []*bundle.Exchange{}
seen := make(map[string]struct{})
hasVariants := make(map[string]bool)

for _, e := range har.Log.Entries {
log.Printf("Processing entry: %q", e.Request.URL)
Expand Down Expand Up @@ -96,11 +96,15 @@ func fromHar(harPath string) ([]*bundle.Exchange, error) {
continue
}

if _, ok := seen[parsedUrl.String()]; ok {
log.Printf("Dropping the entry: exchange for this URL already exists")
// Allow multiple entries for single URL only if all responses have
// Variants: header.
_, thisHasVariants := resh["Variants"]
othersHaveVariants, hasMultipleEntries := hasVariants[parsedUrl.String()]
if hasMultipleEntries && (!thisHasVariants || !othersHaveVariants) {
log.Printf("Dropping the entry: exchange for this URL already exists, and has no Variants header")
continue
}
seen[parsedUrl.String()] = struct{}{}
hasVariants[parsedUrl.String()] = thisHasVariants

e := &bundle.Exchange{
Request: bundle.Request{
Expand Down