feat: use ContentType to control HTML extension
This commit is contained in:
@@ -209,9 +209,22 @@ func (p *Protocol) downloadText(ctx context.Context, reader *bufio.Reader, req *
|
||||
IPVersion: 4,
|
||||
Speed: speed,
|
||||
OutputPath: req.Output,
|
||||
ContentType: gopherContentType(firstType),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// gopherContentType returns the MIME content type for a gopher item type.
|
||||
func gopherContentType(t byte) string {
|
||||
switch t {
|
||||
case typeHTML:
|
||||
return "text/html"
|
||||
case typeTextFile, typeInformation:
|
||||
return "text/plain"
|
||||
default:
|
||||
return "application/octet-stream"
|
||||
}
|
||||
}
|
||||
|
||||
// downloadDirectory formats a directory listing as readable text.
|
||||
func (p *Protocol) downloadDirectory(reader *bufio.Reader, req *core.DownloadRequest, startTime time.Time) (*core.DownloadResult, error) {
|
||||
var writer io.Writer
|
||||
@@ -261,6 +274,7 @@ func (p *Protocol) downloadDirectory(reader *bufio.Reader, req *core.DownloadReq
|
||||
IPVersion: 4,
|
||||
Speed: speed,
|
||||
OutputPath: req.Output,
|
||||
ContentType: "text/plain",
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -313,6 +327,7 @@ func (p *Protocol) downloadBinary(ctx context.Context, reader *bufio.Reader, req
|
||||
IPVersion: 4,
|
||||
Speed: speed,
|
||||
OutputPath: req.Output,
|
||||
ContentType: "application/octet-stream",
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -680,6 +680,7 @@ func (p *Protocol) downloadFile(ctx context.Context, req *core.DownloadRequest,
|
||||
OutputPath: req.Output,
|
||||
Resumed: resumed,
|
||||
ChunksCount: 1,
|
||||
ContentType: resp.Header.Get("Content-Type"),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user