Skip to content

Instantly share code, notes, and snippets.

@DennyLoko
Last active August 7, 2017 00:01
Show Gist options
  • Save DennyLoko/9bed26a6d175d1fd3f6a to your computer and use it in GitHub Desktop.
Save DennyLoko/9bed26a6d175d1fd3f6a to your computer and use it in GitHub Desktop.
This simple application is made to inspect the request sent to other webservers
package main
// This simple application is made to inspect the request sent to other
// webservers. Simply edit your hosts file and point the address to your IP.
// You must be root to use port 80.
// Don't forget to: go get -u github.com/valyala/fasthttp
import (
"flag"
"fmt"
"log"
"github.com/valyala/fasthttp"
)
var (
addr = flag.String("addr", ":8080", "TCP address to listen to")
)
func main() {
flag.Parse()
log.Printf("Starting HTTP server on %q", *addr)
go func() {
if err := fasthttp.ListenAndServe(*addr, requestHandler); err != nil {
log.Fatalf("error in ListenAndServe: %s", err)
}
}()
select {}
}
func requestHandler(ctx *fasthttp.RequestCtx) {
fmt.Println(fmt.Sprintf("---RAW---\n%s\n---/RAW---", &ctx.Request))
ctx.SetContentType("text/plain; charset=utf8")
fmt.Fprintln(ctx, "Ok")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment