Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional verbose debug logging for http requests #29

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"fmt"
"io"
"net/http"
"net/http/httputil"
"strings"
)

Expand Down Expand Up @@ -507,6 +508,13 @@ func (session *Session) sendRequest(request *http.Request) ([]byte, error) {
var response *http.Response
var err error

if session.Debug {
b, _ := httputil.DumpRequest(request, true)
fmt.Println("---[ FACEBOOK REQUEST ]------------------------------")
fmt.Println(string(b))
fmt.Println("-----------------------------------------------------")
}

if session.HttpClient == nil {
response, err = http.DefaultClient.Do(request)
} else {
Expand All @@ -519,6 +527,13 @@ func (session *Session) sendRequest(request *http.Request) ([]byte, error) {

defer response.Body.Close()

if session.Debug {
b, _ := httputil.DumpResponse(response, true)
fmt.Println("---[ FACEBOOK RESPONSE ]-----------------------------")
fmt.Println(string(b))
fmt.Println("-----------------------------------------------------")
}

buf := &bytes.Buffer{}
_, err = io.Copy(buf, response.Body)

Expand Down
1 change: 1 addition & 0 deletions type.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type HttpClient interface {
type Session struct {
HttpClient HttpClient
Version string // facebook versioning.
Debug bool // enable debug logging.

accessToken string // facebook access token. can be empty.
app *App
Expand Down