Skip to content

Commit

Permalink
check error
Browse files Browse the repository at this point in the history
  • Loading branch information
Ольга Машкова committed Sep 13, 2023
1 parent 754d68c commit 55bf6c0
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,34 @@ func (a *transformer) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
newBody["grant_type"] = a.config.GrantType

// add headers to new body
usernameHeader := req.Header.Get("username")
passwordHeader := req.Header.Get("password")

if usernameHeader == "" {
http.Error(rw, "username header missing", http.StatusInternalServerError)
//usernameHeader := req.Header.Get("username")
//passwordHeader := req.Header.Get("password")

//if usernameHeader == "" {
// http.Error(rw, "username header missing", http.StatusInternalServerError)
//}
//newBody["username"] = usernameHeader
//req.Header.Del("username")
//
//if passwordHeader == "" {
// http.Error(rw, "password header missing", http.StatusInternalServerError)
//}
//newBody["password"] = passwordHeader
//req.Header.Del("password")

h := req.Header.Values("username")

usernameHeader, okUser := req.Header["username"]
if !okUser {
http.Error(rw, "username header missing "+h[0], http.StatusInternalServerError)
}
newBody["username"] = usernameHeader
req.Header.Del("username")
newBody["username"] = usernameHeader[0]

if passwordHeader == "" {
passwordHeader, okPass := req.Header["password"]
if !okPass {
http.Error(rw, "password header missing", http.StatusInternalServerError)
}
newBody["password"] = passwordHeader
req.Header.Del("password")
newBody["password"] = passwordHeader[0]

req.Header.Set("Content-Type", a.config.NewContentType)
jsonBody, err := json.Marshal(newBody)
Expand Down

0 comments on commit 55bf6c0

Please sign in to comment.