github.com/blend/go-sdk@v1.20220411.3/webutil/get_port.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package webutil 9 10 import ( 11 "net/http" 12 ) 13 14 // GetPort returns the port for a given request. 15 func GetPort(r *http.Request) string { 16 if r == nil { 17 return "" 18 } 19 20 tryHeader := func(key string) (string, bool) { 21 return HeaderLastValue(r.Header, key) 22 } 23 for _, header := range []string{HeaderXForwardedPort} { 24 if headerVal, ok := tryHeader(header); ok { 25 return headerVal 26 } 27 } 28 return "" 29 }