-
Notifications
You must be signed in to change notification settings - Fork 0
/
forwarder.go
55 lines (48 loc) · 1.16 KB
/
forwarder.go
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
// Copyright 2018 Julien Schmidt. All rights reserved.
// Use of this source code is governed by a MIT-style license that can be found
// in the LICENSE file.
package main
import (
"flag"
"log"
"net/http"
"net/http/httputil"
"net/url"
)
func main() {
var listen string
var proxyStr string
var responderStr string
flag.StringVar(&listen, "listen", "127.0.0.1:8234", "Listen Address")
flag.StringVar(&proxyStr, "proxy_url", "", "Proxy URL")
flag.StringVar(&responderStr, "responder_url", "", "Destination OCSP Responder URL")
flag.Parse()
if proxyStr == "" {
log.Fatal("no Proxy URL set")
}
proxy, err := url.Parse(proxyStr)
if err != nil {
log.Fatal(err)
}
if responderStr == "" {
log.Fatal("no OCSP Responder URL set")
}
responder, err := url.Parse(responderStr)
if err != nil {
log.Fatal(err)
}
err = http.ListenAndServe(listen, &httputil.ReverseProxy{
Director: func(req *http.Request) {
req.URL.Scheme = responder.Scheme
req.URL.Host = responder.Host
req.URL.Path = responder.Path + req.URL.Path
req.Host = responder.Host
},
Transport: &http.Transport{
Proxy: http.ProxyURL(proxy),
},
})
if err != nil {
log.Fatal(err)
}
}