github.com/linapex/ethereum-dpos-chinese@v0.0.0-20190316121959-b78b3a4a1ece/swarm/api/http/roundtripper.go (about)

     1  
     2  //<developer>
     3  //    <name>linapex 曹一峰</name>
     4  //    <email>linapex@163.com</email>
     5  //    <wx>superexc</wx>
     6  //    <qqgroup>128148617</qqgroup>
     7  //    <url>https://jsq.ink</url>
     8  //    <role>pku engineer</role>
     9  //    <date>2019-03-16 12:09:46</date>
    10  //</624342669304270848>
    11  
    12  //
    13  //
    14  //
    15  //
    16  //
    17  //
    18  //
    19  //
    20  //
    21  //
    22  //
    23  //
    24  //
    25  //
    26  //
    27  
    28  package http
    29  
    30  import (
    31  	"fmt"
    32  	"net/http"
    33  
    34  	"github.com/ethereum/go-ethereum/swarm/log"
    35  )
    36  
    37  /*
    38  
    39  
    40  
    41  
    42  
    43   
    44   
    45  
    46  
    47  
    48  
    49  
    50  
    51  
    52  
    53  
    54  
    55  
    56  
    57  
    58  */
    59  
    60  
    61  type RoundTripper struct {
    62  	Host string
    63  	Port string
    64  }
    65  
    66  func (self *RoundTripper) RoundTrip(req *http.Request) (resp *http.Response, err error) {
    67  	host := self.Host
    68  	if len(host) == 0 {
    69  		host = "localhost"
    70  	}
    71  url := fmt.Sprintf("http://
    72  	log.Info(fmt.Sprintf("roundtripper: proxying request '%s' to '%s'", req.RequestURI, url))
    73  	reqProxy, err := http.NewRequest(req.Method, url, req.Body)
    74  	if err != nil {
    75  		return nil, err
    76  	}
    77  	return http.DefaultClient.Do(reqProxy)
    78  }
    79