diff options
| author | jackyzha0 <[email protected]> | 2021-03-07 08:13:10 -0800 |
|---|---|---|
| committer | jackyzha0 <[email protected]> | 2021-03-07 08:13:10 -0800 |
| commit | a9b72af75a9f9cc2be8cdec581133c0e9a301520 (patch) | |
| tree | f8d966ca52919047eb8fa74822af7c5d90d29710 /backend/api | |
| parent | Merge pull request #71 from jackyzha0/http-refactor (diff) | |
| download | ctrl-v-a9b72af75a9f9cc2be8cdec581133c0e9a301520.tar.xz ctrl-v-a9b72af75a9f9cc2be8cdec581133c0e9a301520.zip | |
remove ip from hash calculation
Diffstat (limited to 'backend/api')
| -rw-r--r-- | backend/api/ip.go | 37 | ||||
| -rw-r--r-- | backend/api/routes.go | 5 |
2 files changed, 1 insertions, 41 deletions
diff --git a/backend/api/ip.go b/backend/api/ip.go deleted file mode 100644 index 0d135b3..0000000 --- a/backend/api/ip.go +++ /dev/null @@ -1,37 +0,0 @@ -package api - -import ( - "net" - "net/http" - "strings" -) - -func getIP(r *http.Request) (s string) { - // Get IP from the X-REAL-IP header - ip := r.Header.Get("X-REAL-IP") - netIP := net.ParseIP(ip) - if netIP != nil { - return ip - } - - // Get IP from X-FORWARDED-FOR header - ips := r.Header.Get("X-FORWARDED-FOR") - splitIps := strings.Split(ips, ",") - for _, ip := range splitIps { - netIP := net.ParseIP(ip) - if netIP != nil { - return ip - } - } - - // Get IP from RemoteAddr - ip, _, err := net.SplitHostPort(r.RemoteAddr) - if err != nil { - return - } - netIP = net.ParseIP(ip) - if netIP != nil { - return - } - return -} diff --git a/backend/api/routes.go b/backend/api/routes.go index d05e99a..c4a457f 100644 --- a/backend/api/routes.go +++ b/backend/api/routes.go @@ -30,11 +30,8 @@ func insertFunc(w http.ResponseWriter, r *http.Request) { password := r.FormValue("password") lang := r.FormValue("language") - // get ip - ip := getIP(r) - // insert content - hash, err := db.New(ip, content, expiry, title, password, lang) + hash, err := db.New(content, expiry, title, password, lang) if err != nil { w.WriteHeader(http.StatusBadRequest) fmt.Fprintf(w, "%s", err.Error()) |