~handlerug/handlebot

e2138e35984f582b50a481b58c332afae2841b1f — Umar Getagazov 15 days ago 75e54bf
urlpreview: Parse Content-Disposition

Implements: https://todo.sr.ht/~handlerug/handlebot/15
1 files changed, 6 insertions(+), 0 deletions(-)

M urlpreview/generic.go
M urlpreview/generic.go => urlpreview/generic.go +6 -0
@@ 35,6 35,12 @@ func (p *Previewer) generic(ctx context.Context, u *url.URL) (string, error) {
		if err != nil {
			return mediatype, nil
		}
		dHeader := resp.Header.Get("Content-Disposition")
		_, params, err := mime.ParseMediaType(dHeader)
		if err == nil && params["filename"] != "" {
			return fmt.Sprintf("%s (%s, %s)", params["filename"],
				mediatype, humanize.IBytes(length)), nil
		}
		return fmt.Sprintf("%s (%s)", mediatype, humanize.IBytes(length)), nil
	}