Use cookies saved server side (#188)

* retrieve cookies stored server side

fixed netscape cookies validation pipeline

* code refactoring
This commit is contained in:
Marco Piovanello
2024-08-26 10:09:02 +02:00
committed by GitHub
parent 64df0e0b32
commit bb4db5d342
13 changed files with 247 additions and 152 deletions

View File

@@ -60,6 +60,27 @@ func (h *Handler) Running() http.HandlerFunc {
}
}
func (h *Handler) GetCookies() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
cookies, err := h.service.GetCookies(r.Context())
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
res := &internal.SetCookiesRequest{
Cookies: string(cookies),
}
if err := json.NewEncoder(w).Encode(res); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
}
func (h *Handler) SetCookies() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
@@ -87,6 +108,23 @@ func (h *Handler) SetCookies() http.HandlerFunc {
}
}
func (h *Handler) DeleteCookies() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
err := h.service.SetCookies(r.Context(), "")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
err = json.NewEncoder(w).Encode("ok")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
}
func (h *Handler) AddTemplate() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()