File tree 3 files changed +36
-0
lines changed
3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ /go-proxy
Original file line number Diff line number Diff line change
1
+ module go-proxy
2
+
3
+ go 1.19
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "io"
5
+ "log"
6
+ "net/http"
7
+ "os"
8
+ )
9
+
10
+ func forward (w http.ResponseWriter , r * http.Request ) {
11
+ resp , err := http .DefaultTransport .RoundTrip (r )
12
+ if err != nil {
13
+ log .Print (err )
14
+ http .Error (w , http .StatusText (http .StatusServiceUnavailable ), http .StatusServiceUnavailable )
15
+ return
16
+ }
17
+ for header , values := range resp .Header {
18
+ for _ , value := range values {
19
+ w .Header ().Add (header , value )
20
+ }
21
+ }
22
+ w .WriteHeader (resp .StatusCode )
23
+ io .Copy (w , resp .Body )
24
+ }
25
+
26
+ func main () {
27
+ err := http .ListenAndServe (":8080" , http .HandlerFunc (forward ))
28
+ if err != nil {
29
+ log .Print (err )
30
+ os .Exit (1 )
31
+ }
32
+ }
You can’t perform that action at this time.
0 commit comments