summaryrefslogtreecommitdiff
path: root/dumpClient.go
blob: 2b5dcf439cd6dc08171c87713eba10c9acc17578 (plain)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main

import (
	"fmt"
	"time"
	"net/http"
	"io/ioutil"

	"go.wit.com/log"
)

func dumpClient(r *http.Request) {
	var host, url, proto, addr, agent string

	host = r.Host
	url = r.URL.String()
	proto = r.Proto
	addr = r.RemoteAddr
	agent = r.UserAgent()

	log.Warn(host, proto, addr, url, agent)

	fmt.Fprintln(accessf, time.Now(), host, proto, addr, url, agent)
	// return

	fmt.Fprintln(clientf)
	fmt.Fprintln(clientf, time.Now())
	// Basic request information
	fmt.Fprintln(clientf, "Method:", r.Method)
	fmt.Fprintln(clientf, "URL:", r.URL)
	fmt.Fprintln(clientf, "Protocol:", r.Proto)
	fmt.Fprintln(clientf, "Host:", r.Host)
	fmt.Fprintln(clientf, "Remote Address:", r.RemoteAddr)


	// Headers
	fmt.Fprintln(clientf,"Headers:")
	for name, values := range r.Header {
		for _, value := range values {
			fmt.Fprintln(clientf, "Headers:", name, value)
		}
	}

	// Query parameters
	fmt.Fprintln(clientf, "Query Parameters:")
	for param, values := range r.URL.Query() {
		for _, value := range values {
			fmt.Fprintln(clientf, "Query:", param, value)
		}
	}

	// User-Agent
	fmt.Fprintln(clientf, "User-Agent:", r.UserAgent())

	// Content Length
	fmt.Fprintln(clientf, "Content Length:", r.ContentLength)

	// Cookies
	fmt.Fprintln(clientf,"Cookies:")
	for _, cookie := range r.Cookies() {
		fmt.Fprintln(clientf, cookie.Name, cookie.Value)
	}

	// Request Body (if applicable)
	if r.Body != nil {
		body, err := ioutil.ReadAll(r.Body)
		if err == nil {
			fmt.Fprintln(clientf, "Body:", string(body))
		}
	}
}