You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-login/login/logger/dumper.go

46 lines
1.0 KiB
Go

// Copyright 2017 Drone.IO Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package logger
import (
"net/http"
"net/http/httputil"
"os"
)
// Dumper dumps the http.Request and http.Response
// message payload for debugging purposes.
type Dumper interface {
DumpRequest(*http.Request)
DumpResponse(*http.Response)
}
// DiscardDumper returns a no-op dumper.
func DiscardDumper() Dumper {
return new(discardDumper)
}
type discardDumper struct{}
func (*discardDumper) DumpRequest(*http.Request) {}
func (*discardDumper) DumpResponse(*http.Response) {}
// StandardDumper returns a standard dumper.
func StandardDumper() Dumper {
return new(standardDumper)
}
type standardDumper struct{}
func (*standardDumper) DumpRequest(req *http.Request) {
dump, _ := httputil.DumpRequestOut(req, true)
os.Stdout.Write(dump)
}
func (*standardDumper) DumpResponse(res *http.Response) {
dump, _ := httputil.DumpResponse(res, true)
os.Stdout.Write(dump)
}