github.com/blend/go-sdk@v1.20220411.3/reverseproxy/upstream_option.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" 12 "net/http" 13 14 "github.com/blend/go-sdk/webutil" 15 ) 16 17 // UpstreamOption sets upstream options. 18 type UpstreamOption func(*Upstream) 19 20 // OptUpstreamDial sets the dial options for the upstream. 21 func OptUpstreamDial(opts ...webutil.DialOption) UpstreamOption { 22 return func(u *Upstream) { 23 if u.ReverseProxy.Transport == nil { 24 u.ReverseProxy.Transport = new(http.Transport) 25 } 26 if typed, ok := u.ReverseProxy.Transport.(*http.Transport); ok { 27 dialer := new(net.Dialer) 28 for _, opt := range opts { 29 opt(dialer) 30 } 31 typed.DialContext = dialer.DialContext 32 } 33 } 34 } 35 36 // OptUpstreamModifyResponse sets the dial options for the upstream. 37 func OptUpstreamModifyResponse(modifyResponse func(*http.Response) error) UpstreamOption { 38 return func(u *Upstream) { 39 u.ReverseProxy.ModifyResponse = modifyResponse 40 } 41 }