refactor(net): pass request header (#8031 close #8008)

* refactor(net): pass request header

* feat(proxy): add `Etag` to response header

* refactor
This commit is contained in:
j2rong4cn
2025-03-01 18:35:34 +08:00
committed by GitHub
parent 646c7bcd21
commit 4145734c18
14 changed files with 56 additions and 44 deletions

View File

@ -71,6 +71,7 @@ func checkIfMatch(w http.ResponseWriter, r *http.Request) condResult {
if im == "" {
return condNone
}
r.Header.Del("If-Match")
for {
im = textproto.TrimString(im)
if len(im) == 0 {
@ -98,7 +99,11 @@ func checkIfMatch(w http.ResponseWriter, r *http.Request) condResult {
func checkIfUnmodifiedSince(r *http.Request, modtime time.Time) condResult {
ius := r.Header.Get("If-Unmodified-Since")
if ius == "" || isZeroTime(modtime) {
if ius == "" {
return condNone
}
r.Header.Del("If-Unmodified-Since")
if isZeroTime(modtime) {
return condNone
}
t, err := http.ParseTime(ius)
@ -120,6 +125,7 @@ func checkIfNoneMatch(w http.ResponseWriter, r *http.Request) condResult {
if inm == "" {
return condNone
}
r.Header.Del("If-None-Match")
buf := inm
for {
buf = textproto.TrimString(buf)
@ -150,7 +156,11 @@ func checkIfModifiedSince(r *http.Request, modtime time.Time) condResult {
return condNone
}
ims := r.Header.Get("If-Modified-Since")
if ims == "" || isZeroTime(modtime) {
if ims == "" {
return condNone
}
r.Header.Del("If-Modified-Since")
if isZeroTime(modtime) {
return condNone
}
t, err := http.ParseTime(ims)
@ -174,6 +184,7 @@ func checkIfRange(w http.ResponseWriter, r *http.Request, modtime time.Time) con
if ir == "" {
return condNone
}
r.Header.Del("If-Range")
etag, _ := scanETag(ir)
if etag != "" {
if etagStrongMatch(etag, w.Header().Get("Etag")) {