Skip to content

Commit

Permalink
Remove protocol type and procedure funcs
Browse files Browse the repository at this point in the history
Signed-off-by: Edward McFarlane <[email protected]>
  • Loading branch information
emcfarlane committed Jun 25, 2024
1 parent 7013291 commit 478629f
Showing 1 changed file with 0 additions and 35 deletions.
35 changes: 0 additions & 35 deletions authn.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"context"
"fmt"
"net/http"
"strings"

"connectrpc.com/connect"
)
Expand Down Expand Up @@ -70,40 +69,6 @@ func Errorf(template string, args ...any) *connect.Error {
return connect.NewError(connect.CodeUnauthenticated, fmt.Errorf(template, args...))
}

// Procedure returns the RPC procedure name, in the form "/service/method". If
// the request path does not contain a procedure name, the entire path is
// returned.
func Procedure(request *http.Request) string {
path := strings.TrimSuffix(request.URL.Path, "/")
ultimate := strings.LastIndex(path, "/")
if ultimate < 0 {
return request.URL.Path
}
penultimate := strings.LastIndex(path[:ultimate], "/")
if penultimate < 0 {
return request.URL.Path
}
procedure := path[penultimate:]
if len(procedure) < 4 { // two slashes + service + method
return request.URL.Path
}
return procedure
}

// Protocol returns the RPC protocol. It is one of [connect.ProtocolConnect],
// [connect.ProtocolGRPC], or [connect.ProtocolGRPCWeb].
func Protocol(request *http.Request) string {
ct := request.Header.Get("Content-Type")
switch {
case strings.HasPrefix(ct, "application/grpc-web"):
return connect.ProtocolGRPCWeb
case strings.HasPrefix(ct, "application/grpc"):
return connect.ProtocolGRPC
default:
return connect.ProtocolConnect
}
}

// Middleware is server-side HTTP middleware that authenticates RPC requests.
// In addition to rejecting unauthenticated requests, it can optionally attach
// arbitrary information about the authenticated identity to the context.
Expand Down

0 comments on commit 478629f

Please sign in to comment.