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:
Scott Feldman
2023-06-27 02:25:12 -07:00
committed by deadprogram
parent c3616d9365
commit be25e1a28e
2 changed files with 14 additions and 12 deletions
+9 -7
View File
@@ -11,7 +11,6 @@ package http
import (
"errors"
"fmt"
"internal/safefilepath"
"io"
"io/fs"
"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
// and relative to the directory d.
func (d Dir) Open(name string) (File, error) {
path, err := safefilepath.FromFS(path.Clean("/" + name))
if err != nil {
return nil, errors.New("http: invalid or unsafe file path")
// TINYGO: internal/safefilepath isn't avail until 1.20, so keep pre 1.20
// TINYGO: code here until TinyGo min Go version is >= 1.20.
if filepath.Separator != '/' && strings.ContainsRune(name, filepath.Separator) {
return nil, errors.New("http: invalid character in file path")
}
dir := string(d)
if dir == "" {
dir = "."
}
fullName := filepath.Join(dir, path)
fullName := filepath.Join(dir, filepath.FromSlash(path.Clean("/"+name)))
f, err := os.Open(fullName)
if err != nil {
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 modtime needs to be truncated too.
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 condFalse
@@ -500,7 +501,8 @@ func checkIfModifiedSince(r *Request, modtime time.Time) condResult {
// The Last-Modified header truncates sub-second precision so
// the modtime needs to be truncated too.
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 condTrue
+5 -5
View File
@@ -526,11 +526,12 @@ const TrailerPrefix = "Trailer:"
func (w *response) finalTrailers() Header {
var t Header
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 {
t = make(Header)
}
t[kk] = vv
t[strings.TrimPrefix(k, TrailerPrefix)] = vv
}
}
for _, k := range w.trailers {
@@ -760,8 +761,8 @@ func (cr *connReader) handleReadError(_ error) {
// may be called from multiple goroutines.
func (cr *connReader) closeNotify() {
res := cr.conn.curReq.Load()
if res != nil && !res.didCloseNotify.Swap(true) {
res, _ := cr.conn.curReq.Load().(*response)
if res != nil && atomic.CompareAndSwapInt32(&res.didCloseNotify, 0, 1) {
res.closeNotifyCh <- true
}
}
@@ -2674,7 +2675,6 @@ func (srv *Server) Close() error {
srv.inShutdown.setTrue()
srv.mu.Lock()
defer srv.mu.Unlock()
srv.closeDoneChanLocked()
err := srv.closeListenersLocked()
// Unlock srv.mu while waiting for listenerGroup.