|
|
|
@ -141,7 +141,12 @@ func serveFile(c net.Conn, request *url.URL, filePath string, listDir bool) {
|
|
|
|
|
buf := make([]byte, 261) |
|
|
|
|
n, _ := file.Read(buf) |
|
|
|
|
|
|
|
|
|
// Write header
|
|
|
|
|
// Write response header
|
|
|
|
|
size := int64(-1) |
|
|
|
|
info, err := file.Stat() |
|
|
|
|
if err == nil { |
|
|
|
|
size = info.Size() |
|
|
|
|
} |
|
|
|
|
var mimeType string |
|
|
|
|
if strings.HasSuffix(filePath, ".html") && strings.HasSuffix(filePath, ".htm") { |
|
|
|
|
mimeType = "text/html; charset=utf-8" |
|
|
|
@ -156,7 +161,13 @@ func serveFile(c net.Conn, request *url.URL, filePath string, listDir bool) {
|
|
|
|
|
if mimeType == "" { |
|
|
|
|
mimeType = "text/gemini; charset=utf-8" |
|
|
|
|
} |
|
|
|
|
writeHeader(c, statusSuccess, mimeType) |
|
|
|
|
var meta string |
|
|
|
|
if !config.DisableSize && size >= 0 { |
|
|
|
|
meta = fmt.Sprintf("%s; size=%d", mimeType, size) |
|
|
|
|
} else { |
|
|
|
|
meta = mimeType |
|
|
|
|
} |
|
|
|
|
writeHeader(c, statusSuccess, meta) |
|
|
|
|
|
|
|
|
|
// Write body
|
|
|
|
|
c.Write(buf[:n]) |
|
|
|
|