Skip to content

Commit 9856219

Browse files
committed
adding debug log lines
1 parent f0d294a commit 9856219

File tree

6 files changed

+31
-4
lines changed

6 files changed

+31
-4
lines changed

api/forwarder.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func NewForwarder(host string, port int) *Forwarder {
4242
// ModifyRequest forwards the request to the local API server running at f.port,
4343
// downgrades the scheme to http and marks the request context for skipped logging.
4444
func (f *Forwarder) ModifyRequest(req *http.Request) error {
45+
log.Debugf("api.Forwarder: request: %s", req)
4546
ctx := martian.NewContext(req)
4647
ctx.APIRequest()
4748
ctx.SkipLogging()
@@ -50,7 +51,7 @@ func (f *Forwarder) ModifyRequest(req *http.Request) error {
5051
req.URL.Scheme = "http"
5152
req.URL.Host = fmt.Sprintf("%s:%d", "localhost", f.port)
5253
out := req.URL.String()
53-
log.Infof("api.Forwarder: forwarding %s to %s", in, out)
54+
log.Debugf("api.Forwarder: request forwarding from %s to %s", in, out)
5455

5556
return nil
5657
}

auth/auth_filter.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"sync"
2323

2424
"github.com/google/martian"
25+
"github.com/google/martian/log"
2526
)
2627

2728
// Filter filters RequestModifiers and ResponseModifiers by auth ID.
@@ -98,14 +99,17 @@ func (f *Filter) ResponseModifier(id string) martian.ResponseModifier {
9899
// ModifyRequest runs the RequestModifier for the associated auth ID. If no
99100
// modifier is found for auth ID then auth error is set.
100101
func (f *Filter) ModifyRequest(req *http.Request) error {
102+
log.Debugf("auth.Filter: request: %s", req)
101103
ctx := martian.NewContext(req)
102104
actx := FromContext(ctx)
103105

104106
if reqmod, ok := f.reqmods[actx.ID()]; ok {
107+
log.Debugf("auth.Filter: request match on ID %s", actx.ID())
105108
return reqmod.ModifyRequest(req)
106109
}
107110

108111
if err := f.requireKnownAuth(actx.ID()); err != nil {
112+
log.Debugf("auth.Filter: request error on require auth for ID %s", actx.ID())
109113
actx.SetError(err)
110114
}
111115

@@ -115,14 +119,17 @@ func (f *Filter) ModifyRequest(req *http.Request) error {
115119
// ModifyResponse runs the ResponseModifier for the associated auth ID. If no
116120
// modifier is found for the auth ID then the auth error is set.
117121
func (f *Filter) ModifyResponse(res *http.Response) error {
122+
log.Debugf("auth.Filter: response to request: %s", res.Request)
118123
ctx := martian.NewContext(res.Request)
119124
actx := FromContext(ctx)
120125

121126
if resmod, ok := f.resmods[actx.ID()]; ok {
127+
log.Debugf("auth.Filter: response match on ID %s", actx.ID())
122128
return resmod.ModifyResponse(res)
123129
}
124130

125131
if err := f.requireKnownAuth(actx.ID()); err != nil {
132+
log.Debugf("auth.Filter: response error on require auth for ID %s", actx.ID())
126133
actx.SetError(err)
127134
}
128135

body/body_modifier.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"io/ioutil"
2222
"net/http"
2323

24+
"github.com/google/martian/log"
2425
"github.com/google/martian/parse"
2526
)
2627

@@ -69,6 +70,7 @@ func modifierFromJSON(b []byte) (*parse.Result, error) {
6970

7071
// ModifyRequest sets the Content-Type header and overrides the request body.
7172
func (m *Modifier) ModifyRequest(req *http.Request) error {
73+
log.Debugf("body.Modifier: request: %s", req)
7274
req.Body.Close()
7375

7476
req.Header.Set("Content-Type", m.contentType)
@@ -84,6 +86,7 @@ func (m *Modifier) ModifyRequest(req *http.Request) error {
8486

8587
// ModifyResponse sets the Content-Type header and overrides the response body.
8688
func (m *Modifier) ModifyResponse(res *http.Response) error {
89+
log.Debugf("body.Modifier: response to request: %s", res.Request)
8790
// Replace the existing body, close it first.
8891
res.Body.Close()
8992

cookie/cookie_matcher.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414

1515
package cookie
1616

17-
import "net/http"
17+
import (
18+
"net/http"
19+
20+
"github.com/google/martian/log"
21+
)
1822

1923
// Matcher is a conditonal evalutor of request or
2024
// response cookies to be used in structs that take conditions.
@@ -35,10 +39,12 @@ func NewMatcher(cookie *http.Cookie) *Matcher {
3539
func (m *Matcher) MatchRequest(req *http.Request) bool {
3640
for _, c := range req.Cookies() {
3741
if m.match(c) {
42+
log.Debugf("cookie.Filter: match on request: %s", req)
3843
return true
3944
}
4045
}
4146

47+
log.Debugf("cookie.Filter: no match on request: %s", req)
4248
return false
4349
}
4450

@@ -47,10 +53,12 @@ func (m *Matcher) MatchRequest(req *http.Request) bool {
4753
func (m *Matcher) MatchResponse(res *http.Response) bool {
4854
for _, c := range res.Cookies() {
4955
if m.match(c) {
56+
log.Debugf("cookie.Filter: match on response to request: %s", res.Request)
5057
return true
5158
}
5259
}
5360

61+
log.Debugf("cookie.Filter: no match on response to request: %s", res.Request)
5462
return false
5563
}
5664

cookie/cookie_modifier.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,17 @@ type modifierJSON struct {
4848
// ModifyRequest adds cookie to the request.
4949
func (m *modifier) ModifyRequest(req *http.Request) error {
5050
req.AddCookie(m.cookie)
51-
log.Debugf("cookie: %s: append request cookie: %s", req.URL, m.cookie)
51+
log.Debugf("cookie.Modifier: request: %s", req)
52+
log.Debugf("cookie.Modifier: append request cookie: %s", m.cookie)
5253

5354
return nil
5455
}
5556

5657
// ModifyResponse sets cookie on the response.
5758
func (m *modifier) ModifyResponse(res *http.Response) error {
5859
res.Header.Add("Set-Cookie", m.cookie.String())
59-
log.Debugf("cookie: %s: append response cookie: %s", res.Request.URL, m.cookie)
60+
log.Debugf("cookie.Modifier: response to request: %s", res.Request)
61+
log.Debugf("cookie.Modifier: append response cookie: %s", m.cookie)
6062

6163
return nil
6264
}

header/copy_modifier.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"net/http"
2020

2121
"github.com/google/martian"
22+
"github.com/google/martian/log"
2223
"github.com/google/martian/parse"
2324
"github.com/google/martian/proxyutil"
2425
)
@@ -41,13 +42,18 @@ type copyModifierJSON struct {
4142
func (m *copyModifier) ModifyRequest(req *http.Request) error {
4243
h := proxyutil.RequestHeader(req)
4344

45+
log.Debugf("header.Copy: request: %s", req)
46+
log.Debugf("header.Copy: copying from %s to %s", m.from, m.to)
4447
return h.Set(m.to, h.Get(m.from))
4548
}
4649

4750
// ModifyResponse copies the header in from to the response header for to.
4851
func (m *copyModifier) ModifyResponse(res *http.Response) error {
4952
h := proxyutil.ResponseHeader(res)
5053

54+
log.Debugf("header.Copy: response to request: %s", res.Request)
55+
log.Debugf("header.Copy: copying from %s to %s", m.from, m.to)
56+
5157
return h.Set(m.to, h.Get(m.from))
5258
}
5359

0 commit comments

Comments
 (0)