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

Pass HTTPRequest header to gRPC Hook #813

Merged
merged 1 commit into from
Sep 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion cmd/tusd/cli/hooks/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package hooks

import (
"context"
"net/http"
"time"

grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
Expand Down Expand Up @@ -66,12 +67,22 @@ func marshal(hookReq HookRequest) *pb.HookRequest {
Method: event.HTTPRequest.Method,
Uri: event.HTTPRequest.URI,
RemoteAddr: event.HTTPRequest.RemoteAddr,
// TODO: HEaders
Header: getHeaders(event.HTTPRequest.Header),
},
},
}
}

func getHeaders(httpHeader http.Header) (hookHeader map[string]string) {
hookHeader = make(map[string]string)
for key, val := range httpHeader {
if key != "" && val != nil && len(val) > 0 {
hookHeader[key] = val[0]
}
}
return hookHeader
}

func unmarshal(res *pb.HookResponse) (hookRes HookResponse) {
hookRes.RejectUpload = res.RejectUpload
hookRes.StopUpload = res.StopUpload
Expand Down