github.com/yinchengtsinghua/golang-Eos-dpos-Ethereum@v0.0.0-20190121132951-92cc4225ed8e/swarm/api/http/roundtripper.go (about) 1 2 //此源码被清华学神尹成大魔王专业翻译分析并修改 3 //尹成QQ77025077 4 //尹成微信18510341407 5 //尹成所在QQ群721929980 6 //尹成邮箱 yinc13@mails.tsinghua.edu.cn 7 //尹成毕业于清华大学,微软区块链领域全球最有价值专家 8 //https://mvp.microsoft.com/zh-cn/PublicProfile/4033620 9 // 10 // 11 // 12 // 13 // 14 // 15 // 16 // 17 // 18 // 19 // 20 // 21 // 22 // 23 // 24 25 package http 26 27 import ( 28 "fmt" 29 "net/http" 30 31 "github.com/ethereum/go-ethereum/swarm/log" 32 ) 33 34 /* 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 */ 56 57 58 type RoundTripper struct { 59 Host string 60 Port string 61 } 62 63 func (self *RoundTripper) RoundTrip(req *http.Request) (resp *http.Response, err error) { 64 host := self.Host 65 if len(host) == 0 { 66 host = "localhost" 67 } 68 url := fmt.Sprintf("http:// 69 log.Info(fmt.Sprintf("roundtripper: proxying request '%s' to '%s'", req.RequestURI, url)) 70 reqProxy, err := http.NewRequest(req.Method, url, req.Body) 71 if err != nil { 72 return nil, err 73 } 74 return http.DefaultClient.Do(reqProxy) 75 }