Use io.Copy over ioutil.ReadFile
This commit is contained in:
parent
48f9a206c0
commit
c6c6e544d6
|
@ -5,7 +5,7 @@ import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"mime"
|
"mime"
|
||||||
"net"
|
"net"
|
||||||
|
@ -254,14 +254,16 @@ func serveFile(path string, log *LogEntry, conn net.Conn, config Config, errorLo
|
||||||
mimeType += "; lang=" + config.DefaultLang
|
mimeType += "; lang=" + config.DefaultLang
|
||||||
}
|
}
|
||||||
|
|
||||||
contents, err := ioutil.ReadFile(path)
|
f, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errorLog.Println("Error reading file " + path + ": " + err.Error())
|
errorLog.Println("Error reading file " + path + ": " + err.Error())
|
||||||
conn.Write([]byte("50 Error!\r\n"))
|
conn.Write([]byte("50 Error!\r\n"))
|
||||||
log.Status = 50
|
log.Status = 50
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
conn.Write([]byte(fmt.Sprintf("20 %s\r\n", mimeType)))
|
conn.Write([]byte(fmt.Sprintf("20 %s\r\n", mimeType)))
|
||||||
|
io.Copy(conn, f)
|
||||||
log.Status = 20
|
log.Status = 20
|
||||||
conn.Write(contents)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue