close api response body
This commit is contained in:
parent
8fa8e6844f
commit
1b5ab5659d
2 changed files with 4 additions and 2 deletions
|
|
@ -25,7 +25,7 @@ type Info struct {
|
||||||
|
|
||||||
var ErrNotFound = errors.New("404 not found")
|
var ErrNotFound = errors.New("404 not found")
|
||||||
|
|
||||||
func (f *Forgejo) getFile(ctx context.Context, user, repo, branch, file string) (info Info, content io.Reader, err error) {
|
func (f *Forgejo) getFile(ctx context.Context, user, repo, branch, file string) (info Info, content io.ReadCloser, err error) {
|
||||||
u := f.Server
|
u := f.Server
|
||||||
u.Path = "/api/v1/repos/" + user + "/" + repo + "/raw/" + file
|
u.Path = "/api/v1/repos/" + user + "/" + repo + "/raw/" + file
|
||||||
p := u.Query()
|
p := u.Query()
|
||||||
|
|
@ -55,7 +55,7 @@ func (f *Forgejo) getFile(ctx context.Context, user, repo, branch, file string)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Forgejo) GetFile(ctx context.Context, user, repo, branch, file string) (info Info, content io.Reader, err error) {
|
func (f *Forgejo) GetFile(ctx context.Context, user, repo, branch, file string) (info Info, content io.ReadCloser, err error) {
|
||||||
info, content, err = f.getFile(ctx, user, repo, branch, file)
|
info, content, err = f.getFile(ctx, user, repo, branch, file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|
@ -67,6 +67,7 @@ func (f *Forgejo) GetFile(ctx context.Context, user, repo, branch, file string)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
content.Close()
|
||||||
if bytes.HasPrefix(data, []byte("/")) {
|
if bytes.HasPrefix(data, []byte("/")) {
|
||||||
err = ErrNotFound
|
err = ErrNotFound
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ func (f *Forgejo) handle(w http.ResponseWriter, r *http.Request) {
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer content.Close()
|
||||||
|
|
||||||
trySet(w.Header(), "Etag", info.ETag)
|
trySet(w.Header(), "Etag", info.ETag)
|
||||||
trySet(w.Header(), "Last-Modified", info.LastModified)
|
trySet(w.Header(), "Last-Modified", info.LastModified)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue