mirror of
https://github.com/caddyserver/caddy.git
synced 2026-11-17 13:29:35 +00:00
fileserver: preserve ETag separator
This commit is contained in:
parent
1b14b81323
commit
93db809896
2 changed files with 21 additions and 7 deletions
|
|
@ -1,3 +1,17 @@
|
|||
// Copyright 2015 Matthew Holt and The Caddy Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package fileserver
|
||||
|
||||
import (
|
||||
|
|
@ -12,11 +26,11 @@ type benchFileInfo struct {
|
|||
}
|
||||
|
||||
func (fi benchFileInfo) Name() string { return "file.txt" }
|
||||
func (fi benchFileInfo) Size() int64 { return fi.size }
|
||||
func (fi benchFileInfo) Mode() fs.FileMode { return 0o644 }
|
||||
func (fi benchFileInfo) ModTime() time.Time { return fi.mtime }
|
||||
func (fi benchFileInfo) IsDir() bool { return false }
|
||||
func (fi benchFileInfo) Sys() any { return nil }
|
||||
func (fi benchFileInfo) Size() int64 { return fi.size }
|
||||
func (fi benchFileInfo) Mode() fs.FileMode { return 0o644 }
|
||||
func (fi benchFileInfo) ModTime() time.Time { return fi.mtime }
|
||||
func (fi benchFileInfo) IsDir() bool { return false }
|
||||
func (fi benchFileInfo) Sys() any { return nil }
|
||||
|
||||
func BenchmarkCalculateEtag(b *testing.B) {
|
||||
fi := benchFileInfo{size: 1234567, mtime: time.Unix(1700000000, 123456789)}
|
||||
|
|
|
|||
|
|
@ -779,11 +779,11 @@ func calculateEtag(d os.FileInfo) string {
|
|||
if !usefulModTime(mtime) {
|
||||
return ""
|
||||
}
|
||||
// A quoted etag of two base-36 int64 values is 30 bytes, thus fitting
|
||||
// comfortably in 32 bytes, on the stack to prevent allocations
|
||||
// Two base-36 int64 values, a separator and quotes need at most 31 bytes.
|
||||
var buf [32]byte
|
||||
b := append(buf[:0], '"')
|
||||
b = strconv.AppendInt(b, mtime.UnixNano(), 36)
|
||||
b = append(b, '-')
|
||||
b = strconv.AppendInt(b, d.Size(), 36)
|
||||
b = append(b, '"')
|
||||
return string(b)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue