You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
571 B
Go
31 lines
571 B
Go
2 years ago
|
package internal
|
||
2 years ago
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"net/http"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
const (
|
||
|
metadataHeaderPrefix = "Grpc-Metadata-"
|
||
|
metadataPrefix = "gateway-"
|
||
|
)
|
||
|
|
||
2 years ago
|
// ProcessHeaders builds the headers for the gateway from HTTP headers.
|
||
|
func ProcessHeaders(header http.Header) []string {
|
||
2 years ago
|
var headers []string
|
||
|
|
||
|
for k, v := range header {
|
||
|
if !strings.HasPrefix(k, metadataHeaderPrefix) {
|
||
|
continue
|
||
|
}
|
||
|
|
||
|
key := fmt.Sprintf("%s%s", metadataPrefix, strings.TrimPrefix(k, metadataHeaderPrefix))
|
||
|
for _, vv := range v {
|
||
|
headers = append(headers, key+":"+vv)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return headers
|
||
|
}
|