display xff IPs in log output

This commit is contained in:
mappu 2017-10-15 19:11:13 +13:00
parent 3ca73e3221
commit 57d9b4d324
2 changed files with 9 additions and 7 deletions

View File

@ -10,7 +10,7 @@ import (
func (this *Server) handleView(w http.ResponseWriter, r *http.Request, fileID string) {
err := this.handleViewInternal(w, r, r.URL.Path[len(downloadUrlPrefix):])
if err != nil {
log.Printf("%s View failed: %s\n", r.RemoteAddr, err.Error())
log.Printf("%s View failed: %s\n", this.remoteIP(r), err.Error())
if os.IsNotExist(err) {
http.Error(w, "File not found", 404)
} else {

View File

@ -18,15 +18,17 @@ import (
func (this *Server) handleUpload(w http.ResponseWriter, r *http.Request) {
remoteIP := this.remoteIP(r)
err := r.ParseMultipartForm(this.opts.MaxUploadBytes * 2)
if err != nil {
log.Printf("%s Invalid request: %s\n", r.RemoteAddr, err.Error())
log.Printf("%s Invalid request: %s\n", remoteIP, err.Error())
http.Error(w, "Invalid request", 400)
return
}
if r.MultipartForm == nil || r.MultipartForm.File == nil || len(r.MultipartForm.File["f"]) < 1 {
log.Printf("%s Invalid request: no multipart content\n", r.RemoteAddr)
log.Printf("%s Invalid request: no multipart content\n", remoteIP)
http.Error(w, "Invalid request", 400)
return
}
@ -36,14 +38,14 @@ func (this *Server) handleUpload(w http.ResponseWriter, r *http.Request) {
for _, fhs := range r.MultipartForm.File["f"] {
f, err := fhs.Open()
if err != nil {
log.Printf("%s Internal error: %s\n", r.RemoteAddr, err.Error())
log.Printf("%s Internal error: %s\n", remoteIP, err.Error())
http.Error(w, "Internal error", 500)
return
}
path, err := this.handleUploadFile(f, fhs, this.remoteIP(r))
path, err := this.handleUploadFile(f, fhs, remoteIP)
if err != nil {
log.Printf("%s Upload failed: %s\n", r.RemoteAddr, err.Error())
log.Printf("%s Upload failed: %s\n", remoteIP, err.Error())
http.Error(w, "Upload failed", 500)
}
@ -52,7 +54,7 @@ func (this *Server) handleUpload(w http.ResponseWriter, r *http.Request) {
jb, err := json.Marshal(ret)
if err != nil {
log.Printf("%s Internal error: %s\n", r.RemoteAddr, err.Error())
log.Printf("%s Internal error: %s\n", remoteIP, err.Error())
http.Error(w, "Internal error", 500)
return
}