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

Add passthrough handler #16

Merged
merged 2 commits into from
Sep 7, 2023
Merged

Add passthrough handler #16

merged 2 commits into from
Sep 7, 2023

Conversation

jsha
Copy link
Contributor

@jsha jsha commented Sep 6, 2023

This passes through GET requests other than get-entries to the CT backend. This is particularly useful for some log scanning tools that call /ct/v1/get-sth before beginning their scan.

This is mainly intended as a convenience for small scale testing. In production we plan to bypass this tool for all request paths other than /ct/v1/get-entries.

This passes through GET requests other than get-entries to the CT
backend. This is particularly useful for some log scanning tools that
call `/ct/v1/get-sth` before beginning their scan.

This is mainly intended as a convenience for small scale testing. In
production we plan to bypass this tool for all request paths other than
/ct/v1/get-entries.
@jsha jsha requested review from a team and aarongable and removed request for a team September 6, 2023 19:45
Copy link

@aarongable aarongable left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Once this lands, #17 will need to be updated to pass the mux instead of the handler on line 464.

main.go Outdated
return
}
url := fmt.Sprintf("%s%s", p.logURL, r.URL.Path)
r, err := http.NewRequestWithContext(r.Context(), http.MethodGet, url, nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are reusing the input r *http.Request here.

Suggested change
r, err := http.NewRequestWithContext(r.Context(), http.MethodGet, url, nil)
req, err := http.NewRequestWithContext(r.Context(), http.MethodGet, url, nil)

w.WriteHeader(http.StatusInternalServerError)
fmt.Fprintf(w, "fetching %s: %s\n", url, err)
return
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think resp.Body needs to be closed before we return.

Suggested change
}
}
defer resp.Body.Close()

main.go Outdated
}

w.WriteHeader(resp.StatusCode)
io.Copy(w, resp.Body)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

io.Copy could return an error and it would be going unchecked.

@aarongable aarongable merged commit 7c4dc15 into main Sep 7, 2023
2 checks passed
@aarongable aarongable deleted the passthrough-handler branch September 7, 2023 18:00
jsha added a commit that referenced this pull request Sep 12, 2023
This changed in #16 to accept only the exact request path
`/ct/v1/get-entries`. But it turns out it's easier for the reverse-proxy
configuration if we go back to the old behavior: accepting any request
path ending in `/ct/v1/get-entries`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants