display xff IPs in log output
This commit is contained in:
parent
3ca73e3221
commit
57d9b4d324
@ -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 {
|
||||
|
14
upload.go
14
upload.go
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user