feat: use ContentType to control HTML extension

This commit is contained in:
2026-06-29 11:55:11 +02:00
parent 277178776d
commit 6e58502598
4 changed files with 36 additions and 2 deletions
+15
View File
@@ -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
}