Files
ziti/controller/response/headers.go
T
Andrew Martinez 807a061a93 adds expiration-seconds and expires-at headers
- also adds expiresSeconds to current api session and login
2021-01-14 11:30:44 -05:00

43 lines
1.3 KiB
Go

/*
Copyright NetFoundry, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package response
import (
"fmt"
"github.com/openziti/edge/build"
version3 "github.com/openziti/edge/internal/version"
"net/http"
"strconv"
)
const (
ApiSessionExpirationSecondsHeader = "expiration-seconds"
ApiSessionExpiresAtheader = "expires-at"
)
func AddVersionHeader(rw http.ResponseWriter) {
buildInfo := build.GetBuildInfo()
rw.Header().Set(ZitiControllerVersionHeader, fmt.Sprintf("%s/%s/%s", buildInfo.Version(), buildInfo.Revision(), version3.GetApiVersion()))
}
func AddSessionExpirationHeader(rc *RequestContext) {
if rc.ApiSession != nil {
rc.ResponseWriter.Header().Set(ApiSessionExpirationSecondsHeader, strconv.FormatInt(int64(rc.ApiSession.ExpirationDuration.Seconds()), 10))
rc.ResponseWriter.Header().Set(ApiSessionExpiresAtheader, rc.ApiSession.ExpiresAt.String())
}
}