provider/openstack: Sort request/response headers whilst debugging

This commit is contained in:
Gavin Williams 2017-05-31 11:16:55 +01:00
parent 15704cc6ee
commit 029ff9801b
1 changed files with 11 additions and 2 deletions

View File

@ -7,6 +7,7 @@ import (
"io/ioutil"
"log"
"net/http"
"sort"
"strings"
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs"
@ -75,7 +76,11 @@ func (lrt *LogRoundTripper) logRequest(original io.ReadCloser, headers http.Head
return nil, err
}
log.Printf("[DEBUG] Openstack Request headers:\n%s", strings.Join(RedactHeaders(headers), "\n"))
// Sort the headers for consistency
redactedHeaders := RedactHeaders(headers)
sort.Strings(redactedHeaders)
log.Printf("[DEBUG] Openstack Request headers:\n%s", strings.Join(redactedHeaders, "\n"))
// Handle request contentType
contentType := headers.Get("Content-Type")
@ -92,7 +97,11 @@ func (lrt *LogRoundTripper) logRequest(original io.ReadCloser, headers http.Head
// logResponse will log the HTTP Response details.
// If the body is JSON, it will attempt to be pretty-formatted.
func (lrt *LogRoundTripper) logResponse(original io.ReadCloser, headers http.Header) (io.ReadCloser, error) {
log.Printf("[DEBUG] Openstack Response headers:\n%s", strings.Join(RedactHeaders(headers), "\n"))
// Sort the headers for consistency
redactedHeaders := RedactHeaders(headers)
sort.Strings(redactedHeaders)
log.Printf("[DEBUG] Openstack Response headers:\n%s", strings.Join(redactedHeaders, "\n"))
contentType := headers.Get("Content-Type")
if strings.HasPrefix(contentType, "application/json") {