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

log req body #656

Merged
merged 5 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 2 additions & 2 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ jobs:
os: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: 1.21.x

- name: Check out code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Build
run: go build .
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ jobs:
steps:

- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: 1.21.x

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3.6.0
uses: golangci/golangci-lint-action@v6
with:
version: latest
args: --timeout 5m
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release-binary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ jobs:
runs-on: ubuntu-latest-16-cores
steps:
- name: "Check out code"
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: "Set up Go"
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: 1.21.x

- name: "Create release on GitHub"
uses: goreleaser/goreleaser-action@v4
uses: goreleaser/goreleaser-action@v6
with:
args: "release --rm-dist"
version: latest
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ jobs:
runs-on: ubuntu-latest-16-cores
steps:
- name: "Check out code"
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: 1.21.x

- name: release test
uses: goreleaser/goreleaser-action@v4
uses: goreleaser/goreleaser-action@v6
with:
args: "release --clean --snapshot"
version: latest
Expand Down
2 changes: 1 addition & 1 deletion internal/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,5 @@ func (r *Runner) Close() {
func printDslCompileError(err error) {
gologger.Error().Msgf("error compiling DSL: %s", err)
gologger.Info().Msgf("The available custom DSL functions are:")
gologger.Info().Label("").Msgf(dsl.GetPrintableDslFunctionSignatures(false))
gologger.Info().Label("").Msg(dsl.GetPrintableDslFunctionSignatures(false))
}
21 changes: 15 additions & 6 deletions pkg/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,15 @@ func NewLogger(options *OptionsLogger) *Logger {

// LogRequest and user data
func (l *Logger) LogRequest(req *http.Request, userdata types.UserData) error {
// No-op for now , since proxify isn't intended to fail instead return 502
// and request can be accessed via response.Request
if req == nil {
return nil
}

// send to writer channel
l.asyncqueue <- types.HTTPTransaction{
Userdata: userdata,
Request: req,
}
return nil
}

Expand Down Expand Up @@ -168,10 +175,12 @@ func (l *Logger) AsyncWrite() {
URL: httpData.Request.URL.String(),
}
defer func() {
// write to structured writer with whatever data we have
err := l.sWriter.Write(sData)
if err != nil {
gologger.Warning().Msgf("Error while logging: %s", err)
if sData.Response != nil {
// write to structured writer with whatever data we have
err := l.sWriter.Write(sData)
if err != nil {
gologger.Warning().Msgf("Error while logging: %s", err)
}
}
}()
sRequest, err := types.NewHttpRequestData(httpData.Request)
Expand Down
2 changes: 1 addition & 1 deletion pkg/types/userdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func NewHttpRequestData(req *http.Request) (*HTTPRequest, error) {
httpRequest.Body = string(reqBody)

// Extract raw request
reqdumpNoBody, err := httputil.DumpRequest(req, false)
reqdumpNoBody, err := httputil.DumpRequest(req, true)
if err != nil {
return nil, err
}
Expand Down
6 changes: 6 additions & 0 deletions proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ func NewProxy(options *Options) (*Proxy, error) {

// ModifyRequest
func (p *Proxy) ModifyRequest(req *http.Request) error {
// // Set Content-Length to zero to allow automatic calculation
req.ContentLength = -1

ctx := martian.NewContext(req)
// disable upgrading http connections to https by default
ctx.Session().MarkInsecure()
Expand Down Expand Up @@ -254,6 +257,9 @@ func (*Proxy) removeBrEncoding(req *http.Request) {

// ModifyResponse
func (p *Proxy) ModifyResponse(resp *http.Response) error {
// // Set Content-Length to zero to allow automatic calculation
resp.ContentLength = -1

ctx := martian.NewContext(resp.Request)
var userData *types.UserData
if w, ok := ctx.Get("user-data"); ok {
Expand Down
Loading