-
Notifications
You must be signed in to change notification settings - Fork 225
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 getHeader SSZ support #734
base: develop
Are you sure you want to change the base?
Conversation
I think they are fine, but two things that caught my attention:
First thought that addresses both of these and simplifies things a bit is if we define a doRequest function inside doRequest := func(accept string) (*http.Response, error) {
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, url, nil)
if err != nil {
return nil, err
}
// <insert request prep>
req.Header.Set("Accept", accept)
return m.httpClientGetHeader.Do(req)
} Then we can do something like: // ssz attempt
resp, err := doRequest("application/octet-stream")
if err != nil {
β¦
return
}
// json if relay does not support ssz
if resp.StatusCode == http.StatusNotAcceptable {
resp.Body.Close()
logRelay.Debug("SSZ not accepted, trying JSON")
resp, err = doRequest("application/json")
if err != nil {
β¦
return
}
}
defer resp.Body.Close()
// continue rest of execution
... edit: |
This reverts commit b1cda56.
server/get_header.go
Outdated
} | ||
|
||
// Check if the relay supports SSZ requests | ||
if resp.StatusCode != http.StatusNotAcceptable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this approach works I am not sure about the feasibility in practice due to time constraints, I think it would be best to use q-weighted Accept headers as noted here. To handle the response body, you can look at the Content-Type header sent by server.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh interesting. So this can/should be done in a single request. I'll just forward whatever the client sends & handle the response with Content-Type like you suggest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nflaig if you have time to review this again, I would really appreciate it π
server/get_header.go
Outdated
} | ||
|
||
// Get the response's content type | ||
respContentType := resp.Header.Get("Content-Type") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do all relays properly set this header, otherwise might be best to assume JSON if header is missing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure. Defaulting to JSON sounds like a good idea to me. Will make this change.
|
||
// Add headers from the request to this request. | ||
// This includes Accept and Eth-Consensus-Version, if provided. | ||
for key, values := range header { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my only worry here would be that relays don't properly handle q-weighted Accept headers, which is fine as long as they default to JSON in that case, if they throw an error it would be problematic though
} | ||
|
||
// ParseAcceptHeader parses and sorts the Accept header by q-values. | ||
func ParseAcceptHeader(header string) []AcceptEntry { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you need some test cases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've incorporated these into this PR. But with two changes. If there is no accept header or the accept header isn't in the supported media types, we will default to JSON.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is no accept header or the accept header isn't in the supported media types, we will default to JSON.
we do the same although would return 406 if client only accepts media types we don't support, it's handled here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm yes. I like that idea. Will do the same.
π Summary
This PR adds SSZ support for
getHeader
endpoint. Please see:β I have run these commands
make lint
make test-race
go mod tidy