Add fetch debug endpoint for requesting an url as a user
This commit is contained in:
parent
ca8f5fd483
commit
d8dd5eb671
2 changed files with 34 additions and 0 deletions
|
@ -295,3 +295,36 @@ func kickoffFollow(w http.ResponseWriter, r *http.Request) {
|
|||
dec := json.NewDecoder(r.Body)
|
||||
dec.Decode(&data)
|
||||
}
|
||||
|
||||
func requestAs(w http.ResponseWriter, r *http.Request) {
|
||||
type Inbound struct {
|
||||
Username string
|
||||
TargetUrl string
|
||||
}
|
||||
log := hlog.FromRequest(r)
|
||||
data := Inbound{}
|
||||
dec := json.NewDecoder(r.Body)
|
||||
err := dec.Decode(&data)
|
||||
if err != nil {
|
||||
log.Warn().Err(err).Msg("Failed to decode json body")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
user, err := dbgen.User.GetByUsername(data.Username)
|
||||
if err != nil {
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
res, _, err := webshared.RequestSigned("GET", data.TargetUrl, nil, user)
|
||||
if err != nil {
|
||||
log.Warn().Err(err).Msg("Request failed")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if res.StatusCode != 200 {
|
||||
webutils.ProblemDetailsStatusOnly(w, res.StatusCode)
|
||||
return
|
||||
}
|
||||
body, _ := io.ReadAll(res.Body)
|
||||
fmt.Fprint(w, string(body))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue