-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproxy.go
51 lines (36 loc) · 1021 Bytes
/
proxy.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
package main
import (
"io"
"io/ioutil"
"log"
"net/http"
"os"
"strings"
"time"
)
func myHandler(c http.ResponseWriter, req *http.Request) {
log.Print(req.URL.RequestURI())
if req.URL.RequestURI() == "/" {
http.ServeFile(c, req, "./index.html")
} else if !(strings.HasPrefix(req.URL.RequestURI(), "/2015/Telechargements/ical")) {
http.Error(c, "Tu veux du pain ?", 403)
} else {
resp, _ := http.Get("http://agenda.ecp.fr" + req.URL.RequestURI())
defer resp.Body.Close()
contents, _ := ioutil.ReadAll(resp.Body)
// This is needed for Google Calendar
c.Header().Set("Content-Type", "text/calendar; charset=utf-8")
io.WriteString(c, string(contents))
}
}
func main() {
s := &http.Server{
Addr: ":" + os.Getenv("PORT"),
Handler: http.HandlerFunc(myHandler),
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
MaxHeaderBytes: 1 << 20,
}
log.Print("listening...")
log.Fatal(s.ListenAndServe())
}