Skip to content

Commit 2ca324f

Browse files
committed
improved body updates
1 parent cb7c9c4 commit 2ca324f

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

internals/proxy/middlewares/auth.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ func (data AuthMiddleware) Use() http.Handler {
4444
return
4545
}
4646

47-
log.Info("Request:", req.Method, req.URL.Path)
48-
4947
authHeader := req.Header.Get("Authorization")
5048

5149
authQuery := req.URL.Query().Get("@authorization")

internals/proxy/middlewares/body.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,16 @@ func (data BodyMiddleware) Use() http.Handler {
7474
http.Error(w, "Internal Error", http.StatusInternalServerError)
7575
return
7676
}
77-
}
78-
79-
modifiedBody := string(bodyBytes)
8077

81-
req.Body = io.NopCloser(bytes.NewReader(bodyBytes))
78+
modifiedBody := string(bodyBytes)
8279

83-
req.ContentLength = int64(len(modifiedBody))
84-
req.Header.Set("Content-Length", strconv.Itoa(len(modifiedBody)))
85-
} else {
86-
req.Body = io.NopCloser(bytes.NewReader(bodyBytes))
80+
req.ContentLength = int64(len(modifiedBody))
81+
req.Header.Set("Content-Length", strconv.Itoa(len(modifiedBody)))
82+
}
8783
}
8884

85+
req.Body = io.NopCloser(bytes.NewReader(bodyBytes))
86+
8987
next.ServeHTTP(w, req)
9088
})
9189
}

internals/proxy/middlewares/template.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,26 +127,24 @@ func (data TemplateMiddleware) Use() http.Handler {
127127
log.Debug("Applied Query Templating: ", templatedQuery)
128128
}
129129

130-
modifiedBodyBytes, err := json.Marshal(modifiedBodyData)
130+
bodyBytes, err = json.Marshal(modifiedBodyData)
131131

132132
if err != nil {
133133
log.Error("Could not encode Body: ", err.Error())
134134
http.Error(w, "Internal Error", http.StatusInternalServerError)
135135
return
136136
}
137137

138-
modifiedBody := string(modifiedBodyBytes)
138+
modifiedBody := string(bodyBytes)
139139

140140
log.Debug("Applied Body Templating: ", modifiedBody)
141141

142-
req.Body = io.NopCloser(bytes.NewReader(modifiedBodyBytes))
143-
144142
req.ContentLength = int64(len(modifiedBody))
145143
req.Header.Set("Content-Length", strconv.Itoa(len(modifiedBody)))
146-
} else {
147-
req.Body = io.NopCloser(bytes.NewReader(bodyBytes))
148144
}
149145

146+
req.Body = io.NopCloser(bytes.NewReader(bodyBytes))
147+
150148
reqPath := req.URL.Path
151149
reqPath, _ = url.PathUnescape(reqPath)
152150

0 commit comments

Comments
 (0)