[bugfix] Server and closer bugfixes (#839)

* defer streaming from storage more forcefully

* shut down Server more gracefully

* use command context as server BaseContext
This commit is contained in:
tobi
2022-09-19 13:43:22 +02:00
committed by GitHub
parent c1585d5f8a
commit 3777f5c684
4 changed files with 47 additions and 29 deletions

View File

@@ -85,20 +85,22 @@ func (m *FileServer) ServeFile(c *gin.Context) {
return
}
defer func() {
// if the content is a ReadCloser (ie., it's streamed from storage), close it when we're done
if content.Content != nil {
if closer, ok := content.Content.(io.ReadCloser); ok {
if err := closer.Close(); err != nil {
log.Errorf("ServeFile: error closing readcloser: %s", err)
}
}
}
}()
if content.URL != nil {
c.Redirect(http.StatusFound, content.URL.String())
return
}
defer func() {
// if the content is a ReadCloser, close it when we're done
if closer, ok := content.Content.(io.ReadCloser); ok {
if err := closer.Close(); err != nil {
log.Errorf("ServeFile: error closing readcloser: %s", err)
}
}
}()
// TODO: if the requester only accepts text/html we should try to serve them *something*.
// This is mostly needed because when sharing a link to a gts-hosted file on something like mastodon, the masto servers will
// attempt to look up the content to provide a preview of the link, and they ask for text/html.