mirror of
https://github.com/tinygo-org/net.git
synced 2026-08-18 19:43:57 +00:00
revert some changes going from 1.19.3 to 1.20.5
There are some new features added in Go 1.20 like string.CutPrefix. Those will have to wait to be ported until TinyGo MIN is >= 1.20.
This commit is contained in:
committed by
deadprogram
parent
c3616d9365
commit
be25e1a28e
+9
-7
@@ -11,7 +11,6 @@ package http
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"internal/safefilepath"
|
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"mime"
|
"mime"
|
||||||
@@ -72,15 +71,16 @@ func mapOpenError(originalErr error, name string, sep rune, stat func(string) (f
|
|||||||
// Open implements FileSystem using os.Open, opening files for reading rooted
|
// Open implements FileSystem using os.Open, opening files for reading rooted
|
||||||
// and relative to the directory d.
|
// and relative to the directory d.
|
||||||
func (d Dir) Open(name string) (File, error) {
|
func (d Dir) Open(name string) (File, error) {
|
||||||
path, err := safefilepath.FromFS(path.Clean("/" + name))
|
// TINYGO: internal/safefilepath isn't avail until 1.20, so keep pre 1.20
|
||||||
if err != nil {
|
// TINYGO: code here until TinyGo min Go version is >= 1.20.
|
||||||
return nil, errors.New("http: invalid or unsafe file path")
|
if filepath.Separator != '/' && strings.ContainsRune(name, filepath.Separator) {
|
||||||
|
return nil, errors.New("http: invalid character in file path")
|
||||||
}
|
}
|
||||||
dir := string(d)
|
dir := string(d)
|
||||||
if dir == "" {
|
if dir == "" {
|
||||||
dir = "."
|
dir = "."
|
||||||
}
|
}
|
||||||
fullName := filepath.Join(dir, path)
|
fullName := filepath.Join(dir, filepath.FromSlash(path.Clean("/"+name)))
|
||||||
f, err := os.Open(fullName)
|
f, err := os.Open(fullName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, mapOpenError(err, fullName, filepath.Separator, os.Stat)
|
return nil, mapOpenError(err, fullName, filepath.Separator, os.Stat)
|
||||||
@@ -449,7 +449,8 @@ func checkIfUnmodifiedSince(r *Request, modtime time.Time) condResult {
|
|||||||
// The Last-Modified header truncates sub-second precision so
|
// The Last-Modified header truncates sub-second precision so
|
||||||
// the modtime needs to be truncated too.
|
// the modtime needs to be truncated too.
|
||||||
modtime = modtime.Truncate(time.Second)
|
modtime = modtime.Truncate(time.Second)
|
||||||
if ret := modtime.Compare(t); ret <= 0 {
|
// TINYGO: time.Compare not until Go 1.20
|
||||||
|
if modtime.Before(t) || modtime.Equal(t) {
|
||||||
return condTrue
|
return condTrue
|
||||||
}
|
}
|
||||||
return condFalse
|
return condFalse
|
||||||
@@ -500,7 +501,8 @@ func checkIfModifiedSince(r *Request, modtime time.Time) condResult {
|
|||||||
// The Last-Modified header truncates sub-second precision so
|
// The Last-Modified header truncates sub-second precision so
|
||||||
// the modtime needs to be truncated too.
|
// the modtime needs to be truncated too.
|
||||||
modtime = modtime.Truncate(time.Second)
|
modtime = modtime.Truncate(time.Second)
|
||||||
if ret := modtime.Compare(t); ret <= 0 {
|
// TINYGO: time.Compare not until Go 1.20
|
||||||
|
if modtime.Before(t) || modtime.Equal(t) {
|
||||||
return condFalse
|
return condFalse
|
||||||
}
|
}
|
||||||
return condTrue
|
return condTrue
|
||||||
|
|||||||
+5
-5
@@ -526,11 +526,12 @@ const TrailerPrefix = "Trailer:"
|
|||||||
func (w *response) finalTrailers() Header {
|
func (w *response) finalTrailers() Header {
|
||||||
var t Header
|
var t Header
|
||||||
for k, vv := range w.handlerHeader {
|
for k, vv := range w.handlerHeader {
|
||||||
if kk, found := strings.CutPrefix(k, TrailerPrefix); found {
|
// TINYGO: CutPrefix not available until 1.20
|
||||||
|
if strings.HasPrefix(k, TrailerPrefix) {
|
||||||
if t == nil {
|
if t == nil {
|
||||||
t = make(Header)
|
t = make(Header)
|
||||||
}
|
}
|
||||||
t[kk] = vv
|
t[strings.TrimPrefix(k, TrailerPrefix)] = vv
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, k := range w.trailers {
|
for _, k := range w.trailers {
|
||||||
@@ -760,8 +761,8 @@ func (cr *connReader) handleReadError(_ error) {
|
|||||||
|
|
||||||
// may be called from multiple goroutines.
|
// may be called from multiple goroutines.
|
||||||
func (cr *connReader) closeNotify() {
|
func (cr *connReader) closeNotify() {
|
||||||
res := cr.conn.curReq.Load()
|
res, _ := cr.conn.curReq.Load().(*response)
|
||||||
if res != nil && !res.didCloseNotify.Swap(true) {
|
if res != nil && atomic.CompareAndSwapInt32(&res.didCloseNotify, 0, 1) {
|
||||||
res.closeNotifyCh <- true
|
res.closeNotifyCh <- true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2674,7 +2675,6 @@ func (srv *Server) Close() error {
|
|||||||
srv.inShutdown.setTrue()
|
srv.inShutdown.setTrue()
|
||||||
srv.mu.Lock()
|
srv.mu.Lock()
|
||||||
defer srv.mu.Unlock()
|
defer srv.mu.Unlock()
|
||||||
srv.closeDoneChanLocked()
|
|
||||||
err := srv.closeListenersLocked()
|
err := srv.closeListenersLocked()
|
||||||
|
|
||||||
// Unlock srv.mu while waiting for listenerGroup.
|
// Unlock srv.mu while waiting for listenerGroup.
|
||||||
|
|||||||
Reference in New Issue
Block a user