MCPcopy Index your code
hub / github.com/dnote/dnote / respondWithSession

Function respondWithSession

pkg/server/controllers/helpers.go:270–288  ·  view source on GitHub ↗

respondWithSession makes a HTTP response with the session from the user with the given userID. It sets the HTTP-Only cookie for browser clients and also sends a JSON response for non-browser clients.

(w http.ResponseWriter, statusCode int, session *database.Session)

Source from the content-addressed store, hash-verified

268// respondWithSession makes a HTTP response with the session from the user with the given userID.
269// It sets the HTTP-Only cookie for browser clients and also sends a JSON response for non-browser clients.
270func respondWithSession(w http.ResponseWriter, statusCode int, session *database.Session) {
271 setSessionCookie(w, session.Key, session.ExpiresAt)
272
273 response := SessionResponse{
274 Key: session.Key,
275 ExpiresAt: session.ExpiresAt.Unix(),
276 }
277
278 w.Header().Set("Content-Type", "application/json")
279
280 dat, err := json.Marshal(response)
281 if err != nil {
282 handleJSONError(w, err, "encoding response")
283 return
284 }
285
286 w.WriteHeader(statusCode)
287 w.Write(dat)
288}
289
290// respondJSON encodes the given payload into a JSON format and writes it to the given response writer
291func respondJSON(w http.ResponseWriter, statusCode int, payload interface{}) {

Callers 1

V3LoginMethod · 0.85

Calls 3

setSessionCookieFunction · 0.85
handleJSONErrorFunction · 0.85
WriteHeaderMethod · 0.80

Tested by

no test coverage detected