Beispiel #1
0
func (m *SessionMiddleware) ProcessResponse(env *context.Env) error {
	if env.Session == nil {
		return fmt.Errorf("no session exist")
	}

	env.Session.Expire(m.config.CookieMaxAge)

	if err := env.Session.Save(); err != nil {
		return err
	}

	id, err := EncodeSignID(env.Session.ID(), m.config.secretKey)
	if err != nil {
		return err
	}

	c := &http.Cookie{
		Name:     m.config.CookieName,
		Value:    id,
		Path:     m.config.CookiePath,
		MaxAge:   m.config.CookieMaxAge,
		Secure:   m.config.CookieSecure,
		HttpOnly: m.config.CookieHttpOnly,
	}
	env.SetCookie(c)

	return nil
}
Beispiel #2
0
func (h *TestHandler2) Get(env *context.Env, id string) {
	v := struct {
		ID   string
		Name string
	}{
		id,
		"hello",
	}

	env.Write(v)
}
Beispiel #3
0
func (app *App) processResponse(env *context.Env) error {
	var err error
	for _, m := range app.middlewares {
		if env.IsFinished() {
			return nil
		}

		if err = m.ProcessResponse(env); err != nil {
			return err
		}
	}

	return nil
}
Beispiel #4
0
func (h *TestHandler3) Get(env *context.Env) {
	env.WriteError(http.StatusForbidden, TestHTTPError{http.StatusForbidden, "forbidden", "error"})
}