1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
13 type LoginResponse struct {
14 RedirectLocation string `json:"redirect_location,omitempty"`
15 Token string `json:"token,omitempty"`
16 Message string `json:"message,omitempty"`
17 HTML bytes.Buffer `json:"-"`
20 func (resp LoginResponse) ServeHTTP(w http.ResponseWriter, req *http.Request) {
21 w.Header().Set("Cache-Control", "no-store")
22 if resp.RedirectLocation != "" {
23 w.Header().Set("Location", resp.RedirectLocation)
24 w.WriteHeader(http.StatusFound)
25 } else if resp.Token != "" || resp.Message != "" {
26 w.Header().Set("Content-Type", "application/json")
28 w.WriteHeader(http.StatusUnauthorized)
30 json.NewEncoder(w).Encode(resp)
32 w.Header().Set("Content-Type", "text/html")
33 w.Write(resp.HTML.Bytes())
37 type LogoutResponse struct {
38 RedirectLocation string
41 func (resp LogoutResponse) ServeHTTP(w http.ResponseWriter, req *http.Request) {
42 w.Header().Set("Location", resp.RedirectLocation)
43 w.WriteHeader(http.StatusFound)