mirror of
https://github.com/fosrl/badger.git
synced 2025-05-13 05:40:39 +01:00
added a bunch of logging
This commit is contained in:
parent
f5992bfdff
commit
7a018918f8
1 changed files with 16 additions and 0 deletions
16
main.go
16
main.go
|
@ -75,11 +75,15 @@ func (p *Badger) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||||
req.URL.RawQuery = query.Encode()
|
req.URL.RawQuery = query.Encode()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println("checked for session param")
|
||||||
|
|
||||||
cookies := p.extractCookies(req)
|
cookies := p.extractCookies(req)
|
||||||
if sess != "" {
|
if sess != "" {
|
||||||
cookies.Session = &sess
|
cookies.Session = &sess
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println("extracted cookies")
|
||||||
|
|
||||||
verifyURL := fmt.Sprintf("%s/badger/verify-session", p.apiBaseUrl)
|
verifyURL := fmt.Sprintf("%s/badger/verify-session", p.apiBaseUrl)
|
||||||
|
|
||||||
originalRequestURL := url.QueryEscape(fmt.Sprintf("%s://%s%s", p.getScheme(req), req.Host, req.URL.RequestURI()))
|
originalRequestURL := url.QueryEscape(fmt.Sprintf("%s://%s%s", p.getScheme(req), req.Host, req.URL.RequestURI()))
|
||||||
|
@ -97,12 +101,16 @@ func (p *Badger) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||||
TLS: req.TLS != nil,
|
TLS: req.TLS != nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println("built verify body")
|
||||||
|
|
||||||
jsonData, err := json.Marshal(cookieData)
|
jsonData, err := json.Marshal(cookieData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(rw, "Internal Server Error", http.StatusInternalServerError) // TODO: redirect to error page
|
http.Error(rw, "Internal Server Error", http.StatusInternalServerError) // TODO: redirect to error page
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println("JSON data:", string(jsonData))
|
||||||
|
|
||||||
resp, err := http.Post(verifyURL, "application/json", bytes.NewBuffer(jsonData))
|
resp, err := http.Post(verifyURL, "application/json", bytes.NewBuffer(jsonData))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(rw, "Internal Server Error", http.StatusInternalServerError)
|
http.Error(rw, "Internal Server Error", http.StatusInternalServerError)
|
||||||
|
@ -110,11 +118,15 @@ func (p *Badger) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
fmt.Println("response status code:", resp.StatusCode)
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
http.Error(rw, "Internal Server Error", http.StatusInternalServerError)
|
http.Error(rw, "Internal Server Error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println("de marshalling response")
|
||||||
|
|
||||||
var result VerifyResponse
|
var result VerifyResponse
|
||||||
err = json.NewDecoder(resp.Body).Decode(&result)
|
err = json.NewDecoder(resp.Body).Decode(&result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -122,6 +134,8 @@ func (p *Badger) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println("handling response")
|
||||||
|
|
||||||
if result.RedirectURL != nil && *result.RedirectURL != "" {
|
if result.RedirectURL != nil && *result.RedirectURL != "" {
|
||||||
http.Redirect(rw, req, *result.RedirectURL, http.StatusFound)
|
http.Redirect(rw, req, *result.RedirectURL, http.StatusFound)
|
||||||
return
|
return
|
||||||
|
@ -132,6 +146,8 @@ func (p *Badger) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println("serving authorized")
|
||||||
|
|
||||||
p.next.ServeHTTP(rw, req)
|
p.next.ServeHTTP(rw, req)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue