Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

51 lignes
1.4 KiB

  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. package proxy
  15. import (
  16. "log"
  17. "net/http"
  18. )
  19. // Useful things for when we need to figure out what's actually going on under the hood.
  20. type debugTransport struct {
  21. prefix string
  22. t *http.Transport
  23. }
  24. func (d debugTransport) RoundTrip(req *http.Request) (*http.Response, error) {
  25. log.Printf("proxy %s: %s %s", d.prefix, req.Method, req.URL)
  26. logHeaders(req.Header)
  27. res, err := d.t.RoundTrip(req)
  28. if err != nil {
  29. log.Printf("proxy %s: error %v", d.prefix, err)
  30. } else {
  31. log.Printf("proxy %s: %s", d.prefix, res.Status)
  32. log.Printf("Uncompressed = %v", res.Uncompressed)
  33. log.Printf("ContentLength = %d", res.ContentLength)
  34. logHeaders(res.Header)
  35. log.Printf("Trailers:")
  36. logHeaders(res.Trailer)
  37. }
  38. return res, err
  39. }
  40. func logHeaders(hs http.Header) {
  41. for k, v := range hs {
  42. log.Printf(" %s: %s", k, v)
  43. }
  44. }