Skip to content

Commit 3c3d7b6

Browse files
author
Chris Lenz
committed
Updated make logging better
1 parent ec79d64 commit 3c3d7b6

File tree

4 files changed

+11
-53
lines changed

4 files changed

+11
-53
lines changed

.github/workflows/release.yaml

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,3 @@ jobs:
4747
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4848
GOARCH: amd64
4949
GOOS: darwin
50-
release-windows-386:
51-
name: release windows/386
52-
runs-on: ubuntu-latest
53-
steps:
54-
- uses: actions/checkout@master
55-
- name: compile and release
56-
uses: ngs/go-release.action@v1.0.1
57-
env:
58-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59-
GOARCH: "386"
60-
GOOS: windows
61-
release-windows-amd64:
62-
name: release windows/amd64
63-
runs-on: ubuntu-latest
64-
steps:
65-
- uses: actions/checkout@master
66-
- name: compile and release
67-
uses: ngs/go-release.action@v1.0.1
68-
env:
69-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
70-
GOARCH: amd64
71-
GOOS: windows

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ go clean -i github.com/idefixcert/httpsink
1717
## Download the prebuild files from github
1818

1919
```
20-
wget https://github.com/idefixcert/httpsink/releases/download/1.1.2/httpsink_1.1.2_linux_386.tar.gz
20+
wget https://github.com/idefixcert/httpsink/releases/download/1.1.3/httpsink_1.1.3_linux_386.tar.gz
2121
tar -xzvf httpsink_v1.1.2_linux_386.tar.gz
2222
```

go.mod

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
module github.com/idefixcert/httpsink
22

3-
go 1.13
3+
go 1.21
44

5-
require github.com/gookit/color v1.2.5
5+
require github.com/gookit/color v1.5.4
6+
7+
require (
8+
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
9+
golang.org/x/sys v0.10.0 // indirect
10+
)

httpsink.go

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,15 @@ import (
88
"net/http"
99
"net/http/httptest"
1010
"net/http/httputil"
11-
"net/url"
1211
"time"
1312
)
1413

1514
func main() {
1615
addr := flag.String("addr", ":19091", "HTTP network address")
17-
up := flag.String("up", "", "upstream address for proxy address, if not set, there is no upstream and the sink returns always with 200")
1816
sleep := flag.Duration("sleep", 0, "sleeptime for non proxy function")
1917
flag.Parse()
2018

21-
if *up == "" {
22-
http.HandleFunc("/", rootHandler(*sleep))
23-
} else {
24-
http.HandleFunc("/", proxyHandler(*up))
25-
}
19+
http.HandleFunc("/", rootHandler(*sleep))
2620

2721
log.Printf("Starting server on %s\n", *addr)
2822

@@ -35,26 +29,7 @@ func main() {
3529
func rootHandler(sleep time.Duration) http.HandlerFunc {
3630
return func(w http.ResponseWriter, req *http.Request) {
3731
time.Sleep(sleep)
38-
_, _ = fmt.Fprintf(w, "<h1>Hello World</h1><div>Welcome to whereever you are</div>")
39-
}
40-
}
41-
42-
func proxyHandler(target string) http.HandlerFunc {
43-
return func(w http.ResponseWriter, req *http.Request) {
44-
// parse the targetURL
45-
targetURL, _ := url.Parse(target)
46-
47-
// create the reverse proxy
48-
proxy := httputil.NewSingleHostReverseProxy(targetURL)
49-
50-
// Update the headers to allow for SSL redirection
51-
req.URL.Host = targetURL.Host
52-
req.URL.Scheme = targetURL.Scheme
53-
req.Header.Set("X-Forwarded-Host", req.Header.Get("Host"))
54-
req.Host = targetURL.Host
55-
56-
// Note that ServeHttp is non blocking and uses a go routine under the hood
57-
proxy.ServeHTTP(w, req)
32+
_, _ = fmt.Fprintf(w, "")
5833
}
5934
}
6035

@@ -72,7 +47,7 @@ func logRequest(handler http.Handler) http.Handler {
7247
//log.Printf("%s %s\n", err, string(body))
7348
rec := httptest.NewRecorder()
7449
handler.ServeHTTP(rec, r)
75-
message := fmt.Sprintf("Request:\n%s\nResponse Code: %d\nResponse:\n%s\n\n", string(x), rec.Code, rec.Body.String())
50+
message := fmt.Sprintf("Time:%v\nUrl:\n%sRequest:\n%s\nResponse Code: %d\nResponse:\n%s\n\n", time.Now(), r.URL.Path, string(x), rec.Code, rec.Body.String())
7651
if rec.Code >= 500 {
7752
color.Error.Block(message)
7853
} else if rec.Code >= 400 {

0 commit comments

Comments
 (0)