17171: Exposes bug with a test.
[arvados.git] / sdk / go / arvados / login.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: Apache-2.0
4
5 package arvados
6
7 import (
8         "bytes"
9         "net/http"
10 )
11
12 type LoginResponse struct {
13         RedirectLocation string       `json:"redirect_location,omitempty"`
14         HTML             bytes.Buffer `json:"-"`
15 }
16
17 func (resp LoginResponse) ServeHTTP(w http.ResponseWriter, req *http.Request) {
18         w.Header().Set("Cache-Control", "no-store")
19         if resp.RedirectLocation != "" {
20                 w.Header().Set("Location", resp.RedirectLocation)
21                 w.WriteHeader(http.StatusFound)
22         } else {
23                 w.Header().Set("Content-Type", "text/html")
24                 w.Write(resp.HTML.Bytes())
25         }
26 }
27
28 type LogoutResponse struct {
29         RedirectLocation string `json:"redirect_location,omitempty"`
30 }
31
32 func (resp LogoutResponse) ServeHTTP(w http.ResponseWriter, req *http.Request) {
33         w.Header().Set("Location", resp.RedirectLocation)
34         w.WriteHeader(http.StatusFound)
35 }