Skip to content

Commit

Permalink
Add possibility to overwrite host in a client (#493)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ikryvanos authored Oct 10, 2024
1 parent 6817e07 commit 65c6ba1
Show file tree
Hide file tree
Showing 2 changed files with 225 additions and 160 deletions.
13 changes: 10 additions & 3 deletions services/httpoverrpc/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ import (
"context"
"crypto/tls"
"fmt"
"io"
"net/http"

"github.com/Snowflake-Labs/sansshell/services"
pb "github.com/Snowflake-Labs/sansshell/services/httpoverrpc"
sansshellserver "github.com/Snowflake-Labs/sansshell/services/sansshell/server"
"github.com/Snowflake-Labs/sansshell/telemetry/metrics"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"io"
"net/http"
"strings"
)

// Metrics
Expand Down Expand Up @@ -62,9 +62,16 @@ func (s *server) Host(ctx context.Context, req *pb.HostHTTPRequest) (*pb.HTTPRep
}
// Set a default user agent that can be overridden in the request.
httpReq.Header["User-Agent"] = []string{"sansshell/" + sansshellserver.Version}

for _, header := range req.Request.Headers {
if strings.ToLower(header.Key) == "host" {
// override the host with value from header
httpReq.Host = header.Values[0]
continue
}
httpReq.Header[header.Key] = header.Values
}

client := &http.Client{}
if req.Tlsconfig != nil {
client.Transport = &http.Transport{
Expand Down
Loading

0 comments on commit 65c6ba1

Please sign in to comment.