func (ctx *Context) GetCookie(attr string) string { cookie, err := ctx.r.Cookie(attr) if err != nil { return "" } val, ok := crypto.GetIronValue(attr, cookie.Value, ctx.secret, false) if ok { return val } return "" }
func handle(w http.ResponseWriter, r *http.Request) { if r.URL.Path != "/" { w.WriteHeader(404) w.Write(html404) return } if r.URL.RawQuery == "" { w.Write(htmlIndex) return } params := r.URL.Query() key := params.Get("key") url := params.Get("url") if key == "" || url == "" || isInvalidURL(url) { w.WriteHeader(404) w.Write(html404) return } user, ok := crypto.GetIronValue("files", key, userKey, true) if !ok { w.WriteHeader(401) w.Write(html401) return } hash := sha1.New() hash.Write([]byte(url)) shasum := hash.Sum(nil) // w.Header().Set("Strict-Transport-Security", "max-age=31536000") // w.Header().Set("X-Frame-Options", "DENY") fmt.Fprintf(w, "user: %q\n", digest) fmt.Fprintf(w, "user: %v\n", user) }