github.com/blend/go-sdk@v1.20220411.3/reverseproxy/util.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 reverseproxy 9 10 import ( 11 "net/http" 12 "net/url" 13 "strings" 14 15 "golang.org/x/net/http/httpguts" 16 ) 17 18 // MustParseURL parses a url and panics if it's bad. 19 func MustParseURL(rawURL string) *url.URL { 20 u, err := url.Parse(rawURL) 21 if err != nil { 22 panic(err) 23 } 24 return u 25 } 26 27 // RequestCopy does a shallow copy of a request. 28 func RequestCopy(req *http.Request) *http.Request { 29 outreq := new(http.Request) 30 *outreq = *req // includes shallow copies of maps, but okay 31 if req.ContentLength == 0 { 32 outreq.Body = nil 33 } 34 return outreq 35 } 36 37 // UpgradeType returns the connection upgrade type. 38 // This is used by websockt support. 39 func UpgradeType(h http.Header) string { 40 if !httpguts.HeaderValuesContainsToken(h["Connection"], "Upgrade") { 41 return "" 42 } 43 return strings.ToLower(h.Get("Upgrade")) 44 }