-
Notifications
You must be signed in to change notification settings - Fork 62
Add Invoice skip list #176
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
Conversation
86ddf38
to
0b5dd11
Compare
proxy/service.go
Outdated
// given request. | ||
func (s *Service) SkipInvoiceCreation(r *http.Request) bool { | ||
for _, pathRegexp := range s.AuthSkipInvoiceCreationPaths { | ||
pathRegexp := regexp.MustCompile(pathRegexp) |
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.
Perhaps this could be precompiled for better performance, see:
func MustCompile(str string) *Regexp {
regexp, err := Compile(str)
if err != nil {
panic(`regexp: Compile(` + quote(str) + `): ` + err.Error())
}
return regexp
}
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.
Can probably rebase this on the other PR and then use pre-compiled patterns here too.
proxy/proxy.go
Outdated
@@ -182,6 +183,14 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |||
// resources. | |||
acceptAuth := p.authenticator.Accept(&r.Header, resourceName) | |||
if !acceptAuth { | |||
if skipInvoiceCreation { | |||
addCorsHeaders(w.Header()) | |||
sendDirectResponse(w, r, http.StatusUnauthorized, |
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.
nit: formatting
e9ab581
to
1cda069
Compare
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.
Nice, LGTM 🎉
@@ -135,6 +135,12 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |||
return | |||
} | |||
|
|||
// If the request is a gRPC request, we need to set the Content-Type | |||
// header to application/grpc. | |||
if strings.HasPrefix(r.Header.Get(hdrContentType), hdrTypeGrpc) { |
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, this might fix a long-standing error that we see sometimes. I just hope it doesn't introduce any side effects (I remember the whole header handling for gRPC being super brittle with many weird behaviors).
proxy/service.go
Outdated
// given request. | ||
func (s *Service) SkipInvoiceCreation(r *http.Request) bool { | ||
for _, pathRegexp := range s.AuthSkipInvoiceCreationPaths { | ||
pathRegexp := regexp.MustCompile(pathRegexp) |
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.
Can probably rebase this on the other PR and then use pre-compiled patterns here too.
Prior we would not set the Content-Type header for grpc request, which on failure events would cause the response to be invalid gRPC responses, as the grpc code path in sendDirectResponse expects the Content-Type header to be set. This change fixes the problem by setting the Content-Type header to application/grpc for gRPC requests.
1cda069
to
9023abc
Compare
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.
LGTM 🎉
9023abc
to
b1b0dc5
Compare
This PR adds a new list for the config which will allow skipping the creation of invoices on these specific calls.
This is useful for streaming rpcs, as we can't handle the l402 handshake there (yet?).