feat: verify RpcPath on startup (#2159)
* feat: verify RpcPath on startup * feat: support http header Grpc-Timeout
This commit is contained in:
19
gateway/internal/timeout.go
Normal file
19
gateway/internal/timeout.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
const grpcTimeoutHeader = "Grpc-Timeout"
|
||||
|
||||
// GetTimeout returns the timeout from the header, if not set, returns the default timeout.
|
||||
func GetTimeout(header http.Header, defaultTimeout time.Duration) time.Duration {
|
||||
if timeout := header.Get(grpcTimeoutHeader); len(timeout) > 0 {
|
||||
if t, err := time.ParseDuration(timeout); err == nil {
|
||||
return t
|
||||
}
|
||||
}
|
||||
|
||||
return defaultTimeout
|
||||
}
|
||||
Reference in New Issue
Block a user