From f388f3ac597f22317514fb8ed5258df19130e337 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Fri, 12 Nov 2010 08:40:25 -0500 Subject: [PATCH] Start implementing the proxy service handler. --- src/server.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/server.go b/src/server.go index 33da1ad..3d92b6c 100644 --- a/src/server.go +++ b/src/server.go @@ -23,6 +23,7 @@ import ( var dir, file = path.Split(path.Clean(os.Getenv("_"))) var kFrontEndFiles string = path.Join(dir, "fe") +var gConfig *config.Configuration = nil func indexHandler(connection *http.Conn, request *http.Request) { fd, err := os.Open(path.Join(kFrontEndFiles, "index.html"), os.O_RDONLY, 0) @@ -74,6 +75,18 @@ func serviceHandler(connection *http.Conn, request *http.Request) { } } +func proxyHandler(connection *http.Conn, request *http.Request) { + url := request.FormValue("url") + if len(url) < 1 { + return + } + + for i := range gConfig.ProxyURLs { + allowedURL := gConfig.ProxyURLs[i] + io.WriteString(connection, allowedURL) + } +} + func errorResponse(connection *http.Conn, message string) { message = strings.Replace(message, paths.JailRoot, "/", -1) response := map[string] string { @@ -105,6 +118,9 @@ func RunFrontEnd(config *config.Configuration) { mux.HandleFunc("/", indexHandler) mux.Handle("/fe/", http.FileServer(kFrontEndFiles, "/fe/")) mux.HandleFunc("/service", serviceHandler) + mux.HandleFunc("/proxy", proxyHandler) + + gConfig = config error := http.ListenAndServe(fmt.Sprintf(":%d", config.Port), mux) fmt.Printf("error %v", error) -- 2.22.5