Golang Request.Referer Examples

Golang Request.Referer - 30 examples found. These are the top rated real world Golang examples of net/http.Request.Referer extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
//EditTaskFunc is used to edit tasks, handles "/edit/" URL
func EditTaskFunc(w http.ResponseWriter, r *http.Request) {
	if r.Method != "GET" {
		http.Redirect(w, r, "/", http.StatusBadRequest)
		return
	}

	id, err := strconv.Atoi(r.URL.Path[len("/edit/"):])
	if err != nil {
		log.Println(err)
		http.Redirect(w, r, "/", http.StatusBadRequest)
		return
	}
	redirectURL := utils.GetRedirectUrl(r.Referer())
	username := sessions.GetCurrentUserName(r)
	task, err := db.GetTaskByID(username, id)
	categories := db.GetCategories(username)
	task.Categories = categories
	task.Referer = redirectURL

	if err != nil {
		task.Message = "Error fetching Tasks"
	}
	editTemplate.Execute(w, task)

}
Example #2
0
func (handler *Handler) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
	logMsg := &RequestLog{actualResponseWriter: writer}
	logMsg.RequestHeaders = request.Header
	logMsg.Method = request.Method
	logMsg.Url = request.URL.String()
	logMsg.Host = request.Host
	logMsg.RemoteAddr = request.RemoteAddr
	logMsg.Referer = request.Referer()
	logMsg.UserAgent = request.UserAgent()
	handler.wrappedHandler.ServeHTTP(logMsg, request)
	// Get the resulting values
	if logMsg.ResponseCode == 0 {
		logMsg.ResponseCode = http.StatusOK
	}
	logMsg.ResponseHeaders = writer.Header()
	// Fire off the event to Forest Bus
	jsonMsg, err := json.Marshal(logMsg)
	if err == nil {
		sendErr := handler.msgBatcher.AsyncSendMessage(jsonMsg, nil, nil, handler.blockIfFull)
		if sendErr != nil {
			log.Printf("Warning: Error from AsyncSendMessage: %v\n", sendErr)
		}
	} else {
		log.Printf("Warning: Unable to marshal request information to JSON: %v\n", err)
	}
}
Example #3
0
func (s *loggingSender) send(ctx context.Context, r *http.Request, message string) {
	payload := map[string]interface{}{
		"eventTime":      time.Now().In(time.UTC).Format(time.RFC3339Nano),
		"message":        message,
		"serviceContext": s.serviceContext,
	}
	if r != nil {
		payload["context"] = map[string]interface{}{
			"httpRequest": map[string]interface{}{
				"method":    r.Method,
				"url":       r.Host + r.RequestURI,
				"userAgent": r.UserAgent(),
				"referrer":  r.Referer(),
				"remoteIp":  r.RemoteAddr,
			},
		}
	}
	e := logging.Entry{
		Severity: logging.Error,
		Payload:  payload,
	}
	err := s.logger.LogSync(ctx, e)
	if err != nil {
		log.Println("Error writing error report:", err, "report:", payload)
	}
}
Example #4
0
func Handle(w http.ResponseWriter, r *http.Request) {
	context := appengine.NewContext(r)

	now := time.Now()
	expire := now.AddDate(30, 0, 0)
	zcookie, _ := r.Cookie("z")
	if zcookie == nil {
		zcookie = &http.Cookie{}
		zcookie.Name = "z"
		zcookie.Value = make_hash("127.0.0.1", r.RemoteAddr, now.UnixNano())
		zcookie.Expires = expire
		zcookie.Path = "/"
		zcookie.Domain = config.DOMAIN
		http.SetCookie(w, zcookie)
	}
	context.Infof("%s", zcookie.Value)

	w.Header().Set("Content-type", "image/gif")
	w.Header().Set("Cache-control", "no-cache, must-revalidate")
	w.Header().Set("Expires", "Sat, 26 Jul 1997 05:00:00 GMT")

	fmt.Fprintf(w, "%s", GIF)

	channel.Send(context, "pi", zcookie.Value+"\n"+r.RemoteAddr+"\n"+r.Referer()+"\n"+r.FormValue("r")+"\n"+r.UserAgent())
}
Example #5
0
func Login(session sessions.Session, re render.Render, r *http.Request) {
	client_id := common.Config.OAuth2Client_ID

	letters := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")

	b := make([]rune, 10)
	for i := range b {
		b[i] = letters[rand.Intn(len(letters))]
	}
	session.AddFlash(string(b), "state")

	redirectBack := r.URL.Query().Get("redirect_back")
	ref := r.Referer()

	if redirectBack == "true" && ref != "" {
		session.Set("redirect_to", ref)
	} else {
		session.Set("redirect_to", nil)
	}

	query := url.Values{}
	query.Set("client_id", client_id)
	query.Set("state", string(b))
	query.Set("scope", "repo")

	dest := url.URL{
		Scheme:   "https",
		Host:     "github.com",
		Path:     "/login/oauth/authorize",
		RawQuery: query.Encode(),
	}
	re.Redirect(dest.String())
}
Example #6
0
func RedirectBack(w http.ResponseWriter, r *http.Request) {
	url := r.Referer()
	if url == "" {
		url = "/"
	}
	http.Redirect(w, r, url, http.StatusSeeOther)
}