mirror of
https://github.com/caddyserver/caddy.git
synced 2026-09-08 11:53:49 -04:00
Move from deprecated ioutil to os and io packages (#4364)
This commit is contained in:
1 parent
059fc32f00
commit
c48fadc4a7
26 files changed
+71
-84
No files matched your search
@@ -28,7 +28,6 @@ import (
|
||||
"encoding/pem"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/textproto"
|
||||
@@ -162,7 +161,7 @@ func addHTTPVarsToReplacer(repl *caddy.Replacer, req *http.Request, w http.Respo
|
||||
return "", true
|
||||
}
|
||||
// replace real body with buffered data
|
||||
req.Body = ioutil.NopCloser(buf)
|
||||
req.Body = io.NopCloser(buf)
|
||||
return buf.String(), true
|
||||
|
||||
// original request, before any internal changes
|
||||
|
||||
@@ -30,7 +30,6 @@ import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"mime/multipart"
|
||||
"net"
|
||||
"net/http"
|
||||
@@ -445,7 +444,7 @@ func (c *FCGIClient) Request(p map[string]string, req io.Reader) (resp *http.Res
|
||||
if chunked(resp.TransferEncoding) {
|
||||
resp.Body = clientCloser{c, httputil.NewChunkedReader(rb)}
|
||||
} else {
|
||||
resp.Body = clientCloser{c, ioutil.NopCloser(rb)}
|
||||
resp.Body = clientCloser{c, io.NopCloser(rb)}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"math/rand"
|
||||
"net"
|
||||
@@ -166,7 +165,7 @@ func sendFcgi(reqType int, fcgiParams map[string]string, data []byte, posts map[
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
content, _ = ioutil.ReadAll(resp.Body)
|
||||
content, _ = io.ReadAll(resp.Body)
|
||||
|
||||
log.Println("c: send data length ≈", length, string(content))
|
||||
fcgi.Close()
|
||||
|
||||
@@ -18,7 +18,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
@@ -282,7 +281,7 @@ func (h *Handler) doActiveHealthCheck(dialInfo DialInfo, hostAddr string, host H
|
||||
}
|
||||
defer func() {
|
||||
// drain any remaining body so connection could be re-used
|
||||
_, _ = io.Copy(ioutil.Discard, body)
|
||||
_, _ = io.Copy(io.Discard, body)
|
||||
resp.Body.Close()
|
||||
}()
|
||||
|
||||
@@ -313,7 +312,7 @@ func (h *Handler) doActiveHealthCheck(dialInfo DialInfo, hostAddr string, host H
|
||||
|
||||
// if body does not match regex, mark down
|
||||
if h.HealthChecks.Active.bodyRegexp != nil {
|
||||
bodyBytes, err := ioutil.ReadAll(body)
|
||||
bodyBytes, err := io.ReadAll(body)
|
||||
if err != nil {
|
||||
h.HealthChecks.Active.logger.Info("failed to read response body",
|
||||
zap.String("host", hostAddr),
|
||||
|
||||
@@ -20,10 +20,10 @@ import (
|
||||
"crypto/x509"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
weakrand "math/rand"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
@@ -364,7 +364,7 @@ func (t TLSConfig) MakeTLSClientConfig(ctx caddy.Context) (*tls.Config, error) {
|
||||
rootPool.AddCert(caCert)
|
||||
}
|
||||
for _, pemFile := range t.RootCAPEMFiles {
|
||||
pemData, err := ioutil.ReadFile(pemFile)
|
||||
pemData, err := os.ReadFile(pemFile)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed reading ca cert: %v", err)
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ package caddyhttp
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strconv"
|
||||
@@ -44,7 +44,7 @@ func TestStaticResponseHandler(t *testing.T) {
|
||||
}
|
||||
|
||||
resp := w.Result()
|
||||
respBody, _ := ioutil.ReadAll(resp.Body)
|
||||
respBody, _ := io.ReadAll(resp.Body)
|
||||
|
||||
if resp.StatusCode != http.StatusNotFound {
|
||||
t.Errorf("expected status %d but got %d", http.StatusNotFound, resp.StatusCode)
|
||||
|
||||
@@ -17,7 +17,6 @@ package templates
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -118,7 +117,7 @@ func TestImport(t *testing.T) {
|
||||
// create files for test case
|
||||
if test.fileName != "" {
|
||||
absFilePath := filepath.Join(fmt.Sprintf("%s", context.Root), test.fileName)
|
||||
if err := ioutil.WriteFile(absFilePath, []byte(test.fileContent), os.ModePerm); err != nil {
|
||||
if err := os.WriteFile(absFilePath, []byte(test.fileContent), os.ModePerm); err != nil {
|
||||
os.Remove(absFilePath)
|
||||
t.Fatalf("Test %d: Expected no error creating file, got: '%s'", i, err.Error())
|
||||
}
|
||||
@@ -198,7 +197,7 @@ func TestInclude(t *testing.T) {
|
||||
// create files for test case
|
||||
if test.fileName != "" {
|
||||
absFilePath := filepath.Join(fmt.Sprintf("%s", context.Root), test.fileName)
|
||||
if err := ioutil.WriteFile(absFilePath, []byte(test.fileContent), os.ModePerm); err != nil {
|
||||
if err := os.WriteFile(absFilePath, []byte(test.fileContent), os.ModePerm); err != nil {
|
||||
os.Remove(absFilePath)
|
||||
t.Fatalf("Test %d: Expected no error creating file, got: '%s'", i, err.Error())
|
||||
}
|
||||
@@ -357,13 +356,13 @@ func TestFileListing(t *testing.T) {
|
||||
|
||||
// create files for test case
|
||||
if test.fileNames != nil {
|
||||
dirPath, err = ioutil.TempDir(fmt.Sprintf("%s", context.Root), "caddy_ctxtest")
|
||||
dirPath, err = os.MkdirTemp(fmt.Sprintf("%s", context.Root), "caddy_ctxtest")
|
||||
if err != nil {
|
||||
t.Fatalf("Test %d: Expected no error creating directory, got: '%s'", i, err.Error())
|
||||
}
|
||||
for _, name := range test.fileNames {
|
||||
absFilePath := filepath.Join(dirPath, name)
|
||||
if err = ioutil.WriteFile(absFilePath, []byte(""), os.ModePerm); err != nil {
|
||||
if err = os.WriteFile(absFilePath, []byte(""), os.ModePerm); err != nil {
|
||||
os.RemoveAll(dirPath)
|
||||
t.Fatalf("Test %d: Expected no error creating file, got: '%s'", i, err.Error())
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user