Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Unified Diff: sky/tools/skygo/sky_server.go

Issue 1059113004: Teach sky_server not to serve up /.git (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/tools/skygo/README ('k') | sky/tools/skygo/sky_server.sha1 » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/tools/skygo/sky_server.go
diff --git a/sky/tools/skygo/sky_server.go b/sky/tools/skygo/sky_server.go
index 482e6694a2712bad90d58bb6a3a64d9794eeb40b..1327a19d3c6c8628ba2a5b7c18ec12d9aca33fc4 100644
--- a/sky/tools/skygo/sky_server.go
+++ b/sky/tools/skygo/sky_server.go
@@ -5,83 +5,87 @@
package main
import (
- "flag"
- "fmt"
- "io/ioutil"
- "net/http"
- "os"
- "path"
- "path/filepath"
- "strings"
+ "flag"
+ "fmt"
+ "io/ioutil"
+ "net/http"
+ "os"
+ "path"
+ "path/filepath"
+ "strings"
)
type skyHandlerRoot struct {
- root string
+ root string
}
func skyHandler(root string) http.Handler {
- return &skyHandlerRoot{root}
+ return &skyHandlerRoot{root}
}
func (handler *skyHandlerRoot) ServeHTTP(w http.ResponseWriter, r *http.Request) {
- path := path.Join(handler.root, r.URL.Path)
- if strings.HasSuffix(path, ".sky") {
- w.Header().Set("Content-Type", "text/sky")
- }
- w.Header().Set("Cache-Control", "no-cache")
- http.ServeFile(w, r, path)
+ if strings.HasPrefix(r.URL.Path, "/.git") {
+ w.WriteHeader(http.StatusNotFound)
+ return
+ }
+ path := path.Join(handler.root, r.URL.Path)
+ if strings.HasSuffix(path, ".sky") {
+ w.Header().Set("Content-Type", "text/sky")
+ }
+ w.Header().Set("Cache-Control", "no-cache")
+ http.ServeFile(w, r, path)
}
func usage() {
- fmt.Fprintf(os.Stderr, "Usage: sky_server [flags] MOJO_SRC_ROOT PORT\n\n")
- fmt.Fprintf(os.Stderr, "launches a basic http server with mappings into the\n")
- fmt.Fprintf(os.Stderr, "mojo repository for framework/service paths.\n")
- fmt.Fprintf(os.Stderr, "[flags] MUST be before arguments, because go:flag.\n\n")
- flag.PrintDefaults()
- os.Exit(2)
+ fmt.Fprintf(os.Stderr, "Usage: sky_server [flags] MOJO_SRC_ROOT PORT\n\n")
+ fmt.Fprintf(os.Stderr, "launches a basic http server with mappings into the\n")
+ fmt.Fprintf(os.Stderr, "mojo repository for framework/service paths.\n")
+ fmt.Fprintf(os.Stderr, "[flags] MUST be before arguments, because go:flag.\n\n")
+ flag.PrintDefaults()
+ os.Exit(2)
}
func addMapping(from_path string, to_path string) {
- // Print to stderr to it's more obvious what this binary does.
- fmt.Fprintf(os.Stderr, " %s -> %s\n", from_path, to_path)
- http.Handle(from_path, http.StripPrefix(from_path, skyHandler(to_path)))
+ // Print to stderr to it's more obvious what this binary does.
+ fmt.Fprintf(os.Stderr, " %s -> %s\n", from_path, to_path)
+ http.Handle(from_path, http.StripPrefix(from_path, skyHandler(to_path)))
}
func main() {
- var configuration = flag.String("t", "Release", "The target configuration (i.e. Release or Debug)")
-
- flag.Parse()
- flag.Usage = usage
- // The built-in go:flag is awful. It only allows short-name arguments
- // and they *must* be before any unnamed arguments. There are better ones:
- // https://godoc.org/github.com/jessevdk/go-flags
- // but for now we're using raw-go.
- if flag.NArg() != 3 {
- usage()
- }
-
- root, _ := filepath.Abs(flag.Arg(0))
- port := flag.Arg(1)
- packageRoot := flag.Arg(2)
-
- // genRoot should not be needed once we figure out how mojom generation
- // for sdk users should work.
- genRoot := path.Join(root, "out", *configuration, "gen")
-
- fmt.Fprintf(os.Stderr, "Mappings for localhost:%s:\n", port)
-
- fmt.Fprintf(os.Stderr, " / -> %s\n", root)
- http.Handle("/", skyHandler(root))
-
- fmt.Fprintf(os.Stderr, " /echo_post -> custom echo handler\n")
- http.HandleFunc("/echo_post", func(w http.ResponseWriter, r *http.Request) {
- defer r.Body.Close()
- body, _ := ioutil.ReadAll(r.Body)
- w.Write(body)
- })
-
- addMapping("/gen/", genRoot)
- addMapping("/packages/", packageRoot)
-
- http.ListenAndServe(":" + port, nil)
+ var configuration = flag.String("t", "Release", "The target configuration (i.e. Release or Debug)")
+
+ flag.Parse()
+ flag.Usage = usage
+ // The built-in go:flag is awful. It only allows short-name arguments
+ // and they *must* be before any unnamed arguments. There are better ones:
+ // https://godoc.org/github.com/jessevdk/go-flags
+ // but for now we're using raw-go.
+ if flag.NArg() != 3 {
+ usage()
+ }
+
+ root, _ := filepath.Abs(flag.Arg(0))
+ port := flag.Arg(1)
+ packageRoot := flag.Arg(2)
+
+ // genRoot should not be needed once we figure out how mojom generation
+ // for sdk users should work.
+ genRoot := path.Join(root, "out", *configuration, "gen")
+
+ fmt.Fprintf(os.Stderr, "Mappings for localhost:%s:\n", port)
+
+ fmt.Fprintf(os.Stderr, " / -> %s\n", root)
+ http.Handle("/", skyHandler(root))
+
+ fmt.Fprintf(os.Stderr, " /echo_post -> custom echo handler\n")
+ http.HandleFunc("/echo_post", func(w http.ResponseWriter, r *http.Request) {
+ defer r.Body.Close()
+ body, _ := ioutil.ReadAll(r.Body)
+ w.Write(body)
+ })
+
+ addMapping("/gen/", genRoot)
+ addMapping("/packages/", packageRoot)
+
+ http.ListenAndServe(":"+port, nil)
}
« no previous file with comments | « sky/tools/skygo/README ('k') | sky/tools/skygo/sky_server.sha1 » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698