Skip to content

Commit

Permalink
feat: fetch content and serve it
Browse files Browse the repository at this point in the history
  • Loading branch information
neurosnap committed May 18, 2024
1 parent 16a9a5b commit a25330d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pgs/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,21 @@ func (h *AssetHandler) handle(w http.ResponseWriter, r *http.Request) {
)
http.Redirect(w, r, fp.Filepath, fp.Status)
return
} else if hasProtocol(fp.Filepath) {
// fetch content from url and serve it
resp, err := http.Get(fp.Filepath)
if err != nil {
http.Error(w, "404 not found", http.StatusNotFound)
return
}

w.Header().Set("content-type", resp.Header.Get("content-type"))
w.WriteHeader(status)
_, err = io.Copy(w, resp.Body)
if err != nil {
h.Logger.Error("io copy", "err", err.Error())
}
return
}

attempts = append(attempts, fp.Filepath)
Expand Down

0 comments on commit a25330d

Please sign in to comment.