Skip to content
Snippets Groups Projects
Select Git revision
  • 3d2f0f5ce1b61d16daa3f467ee4f15fc32365c5b
  • master default protected
  • 1.31
  • 4.24.3
  • 4.24.2
  • 4.24.1
  • 4.24.0
  • 4.23.6
  • 4.23.5
  • 4.23.4
  • 4.23.3
  • 4.23.2
  • 4.23.1
  • 4.23.0
  • 4.22.3
  • 4.22.2
  • 4.22.1
  • 4.22.0
  • 4.21.0
  • 4.20.1
  • 4.20.0
  • 4.19.0
  • 4.18.0
23 results

constants.mjs

Blame
  • helpers.go NaN GiB
    package main
    
    import (
    	"encoding/json"
    	"net/http"
    	"net/url"
    )
    
    func getOrigin(r *http.Request) string {
    	origin := r.Header.Get("X-Forwarded-For")
    	if origin == "" {
    		origin = r.RemoteAddr
    	}
    	return origin
    }
    
    func getURL(r *http.Request) string {
    	scheme := r.Header.Get("X-Forwarded-Proto")
    	if scheme == "" {
    		scheme = r.Header.Get("X-Forwarded-Protocol")
    	}
    	if scheme == "" && r.Header.Get("X-Forwarded-Ssl") == "on" {
    		scheme = "https"
    	}
    	if scheme == "" {
    		scheme = "http"
    	}
    
    	host := r.URL.Host
    	if host == "" {
    		host = r.Host
    	}
    
    	u := &url.URL{
    		Scheme:     scheme,
    		Opaque:     r.URL.Opaque,
    		User:       r.URL.User,
    		Host:       host,
    		Path:       r.URL.Path,
    		RawPath:    r.URL.RawPath,
    		ForceQuery: r.URL.ForceQuery,
    		RawQuery:   r.URL.RawQuery,
    		Fragment:   r.URL.Fragment,
    	}
    	return u.String()
    }
    
    func writeResponse(w http.ResponseWriter, r *http.Request, resp *Resp) {
    	resp.Origin = getOrigin(r)
    	resp.URL = getURL(r)
    	body, _ := json.Marshal(resp)
    	writeJSON(w, body)
    }
    
    func writeJSON(w http.ResponseWriter, body []byte) {
    	w.Header().Set("Content-Type", "application/json; encoding=utf-8")
    	w.Write(body)
    }