mirror of
https://code.rocketnine.space/tslocum/twins.git
synced 2024-11-27 13:28:15 +01:00
Include size of response body in media type header
This commit is contained in:
parent
dc58324dff
commit
2b7e21666b
3 changed files with 20 additions and 2 deletions
|
@ -62,6 +62,11 @@ certbot certonly --config-dir /home/www/certs \
|
||||||
Provide the path to the certificate file at `certs/live/$DOMAIN/fullchain.pem`
|
Provide the path to the certificate file at `certs/live/$DOMAIN/fullchain.pem`
|
||||||
and the private key file at `certs/live/$DOMAIN/privkey.pem` to twins.
|
and the private key file at `certs/live/$DOMAIN/privkey.pem` to twins.
|
||||||
|
|
||||||
|
### DisableSize
|
||||||
|
|
||||||
|
The size of the response body is included in the media type header by default.
|
||||||
|
Set this option to `true` to disable this feature.
|
||||||
|
|
||||||
### Path
|
### Path
|
||||||
|
|
||||||
#### Resources
|
#### Resources
|
||||||
|
|
|
@ -57,6 +57,8 @@ type serverConfig struct {
|
||||||
|
|
||||||
Hosts map[string]*hostConfig
|
Hosts map[string]*hostConfig
|
||||||
|
|
||||||
|
DisableSize bool
|
||||||
|
|
||||||
hostname string
|
hostname string
|
||||||
port int
|
port int
|
||||||
fcgiPools map[string]gofast.ConnFactory
|
fcgiPools map[string]gofast.ConnFactory
|
||||||
|
|
|
@ -141,7 +141,12 @@ func serveFile(c net.Conn, request *url.URL, filePath string, listDir bool) {
|
||||||
buf := make([]byte, 261)
|
buf := make([]byte, 261)
|
||||||
n, _ := file.Read(buf)
|
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
|
var mimeType string
|
||||||
if strings.HasSuffix(filePath, ".html") && strings.HasSuffix(filePath, ".htm") {
|
if strings.HasSuffix(filePath, ".html") && strings.HasSuffix(filePath, ".htm") {
|
||||||
mimeType = "text/html; charset=utf-8"
|
mimeType = "text/html; charset=utf-8"
|
||||||
|
@ -156,7 +161,13 @@ func serveFile(c net.Conn, request *url.URL, filePath string, listDir bool) {
|
||||||
if mimeType == "" {
|
if mimeType == "" {
|
||||||
mimeType = "text/gemini; charset=utf-8"
|
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
|
// Write body
|
||||||
c.Write(buf[:n])
|
c.Write(buf[:n])
|
||||||
|
|
Loading…
Reference in a new issue