diff options
author | 2022-09-19 13:43:22 +0200 | |
---|---|---|
committer | 2022-09-19 12:43:22 +0100 | |
commit | 3777f5c68448992a6ed8230f40713d3b31da0413 (patch) | |
tree | 3b56e932503b2dec6ca613e5d8abcfe074b4dfc2 /internal/api/client/fileserver | |
parent | [bugfix] Fix domains not being unblockable, log internal server errors from A... (diff) | |
download | gotosocial-3777f5c68448992a6ed8230f40713d3b31da0413.tar.xz |
[bugfix] Server and closer bugfixes (#839)
* defer streaming from storage more forcefully
* shut down Server more gracefully
* use command context as server BaseContext
Diffstat (limited to 'internal/api/client/fileserver')
-rw-r--r-- | internal/api/client/fileserver/servefile.go | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/internal/api/client/fileserver/servefile.go b/internal/api/client/fileserver/servefile.go index 0858af3ce..236a2d8ac 100644 --- a/internal/api/client/fileserver/servefile.go +++ b/internal/api/client/fileserver/servefile.go @@ -85,20 +85,22 @@ func (m *FileServer) ServeFile(c *gin.Context) { return } - 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) + // 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 + } + // 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. |