-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttpmirror.go
More file actions
49 lines (38 loc) · 835 Bytes
/
Copy pathhttpmirror.go
File metadata and controls
49 lines (38 loc) · 835 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"flag"
"fmt"
"log"
"net/http"
"net/http/httputil"
"os"
)
func main() {
http.HandleFunc("/", httpmirror)
log.Fatal(http.ListenAndServe(":"+port(), nil))
}
func httpmirror(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Mirror mirror on the wall.\nDid you hear my browser call?\n\n"))
var dump, _ = httputil.DumpRequest(r, true)
write(dump)
w.Write(dump)
}
func port() string {
port := flag.String("port", "3000", "Enter port for web server")
flag.Parse()
fmt.Println("Using port: ", *port)
return *port
}
func write(s []byte) {
f, err1 := os.OpenFile("httpmirror.log", os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
if err1 != nil {
fmt.Println(err1.Error())
}
defer f.Close()
fmt.Println(string(s))
_, err2 := f.Write(s)
if err2 != nil {
log.Panic(err2)
}
f.Sync()
}