...

Source file src/cloud.google.com/go/httpreplay/internal/proxy/debug.go

Documentation: cloud.google.com/go/httpreplay/internal/proxy

     1  // Copyright 2018 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package proxy
    16  
    17  import (
    18  	"log"
    19  	"net/http"
    20  )
    21  
    22  // Useful things for when we need to figure out what's actually going on under the hood.
    23  
    24  type debugTransport struct {
    25  	prefix string
    26  	t      *http.Transport
    27  }
    28  
    29  func (d debugTransport) RoundTrip(req *http.Request) (*http.Response, error) {
    30  	log.Printf("proxy %s: %s %s", d.prefix, req.Method, req.URL)
    31  	logHeaders(req.Header)
    32  	res, err := d.t.RoundTrip(req)
    33  	if err != nil {
    34  		log.Printf("proxy %s: error %v", d.prefix, err)
    35  	} else {
    36  		log.Printf("proxy %s: %s", d.prefix, res.Status)
    37  		log.Printf("Uncompressed = %v", res.Uncompressed)
    38  		log.Printf("ContentLength = %d", res.ContentLength)
    39  		logHeaders(res.Header)
    40  		log.Printf("Trailers:")
    41  		logHeaders(res.Trailer)
    42  	}
    43  	return res, err
    44  }
    45  
    46  func logHeaders(hs http.Header) {
    47  	for k, v := range hs {
    48  		log.Printf("    %s: %s", k, v)
    49  	}
    50  }
    51  

View as plain text