-
-
Save nimezhu/93e12a52f075d3453691 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// go build -ldflags "-s -w" -o index.cgi cgi.go | |
package main | |
import ( | |
"fmt" | |
"net/http" | |
"net/http/cgi" | |
) | |
func main() { | |
if err := cgi.Serve(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
header := w.Header() | |
header.Set("Content-Type", "text/plain; charset=utf-8") | |
fmt.Fprintln(w, "Method:", r.Method) | |
fmt.Fprintln(w, "URL:", r.URL.String()) | |
query := r.URL.Query() | |
for k := range query { | |
fmt.Fprintln(w, "Query", k+":", query.Get(k)) | |
} | |
r.ParseForm() | |
form := r.Form | |
for k := range form { | |
fmt.Fprintln(w, "Form", k+":", form.Get(k)) | |
} | |
post := r.PostForm | |
for k := range post { | |
fmt.Fprintln(w, "PostForm", k+":", post.Get(k)) | |
} | |
fmt.Fprintln(w, "RemoteAddr:", r.RemoteAddr) | |
if referer := r.Referer(); len(referer) > 0 { | |
fmt.Fprintln(w, "Referer:", referer) | |
} | |
if ua := r.UserAgent(); len(ua) > 0 { | |
fmt.Fprintln(w, "UserAgent:", ua) | |
} | |
for _, cookie := range r.Cookies() { | |
fmt.Fprintln(w, "Cookie", cookie.Name+":", cookie.Value, cookie.Path, cookie.Domain, cookie.RawExpires) | |
} | |
})); err != nil { | |
fmt.Println(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment