summaryrefslogtreecommitdiff
path: root/gemini/response.go
diff options
context:
space:
mode:
authortjpcc <tjp@ctrl-c.club>2023-05-01 07:56:25 -0600
committertjpcc <tjp@ctrl-c.club>2023-05-01 07:56:25 -0600
commit9a2da81b11ad0064cca24ce7974827d032309369 (patch)
tree4313224dc089208423e78bffc3ec50833e35bcea /gemini/response.go
parent21e2758145d100d74013060f7090d84679cae683 (diff)
name change gus -> sliderule
Diffstat (limited to 'gemini/response.go')
-rw-r--r--gemini/response.go100
1 files changed, 50 insertions, 50 deletions
diff --git a/gemini/response.go b/gemini/response.go
index b8797da..9d4ede1 100644
--- a/gemini/response.go
+++ b/gemini/response.go
@@ -8,7 +8,7 @@ import (
"strconv"
"sync"
- "tildegit.org/tjp/gus"
+ sr "tildegit.org/tjp/sliderule"
)
// ResponseCategory represents the various types of gemini responses.
@@ -43,32 +43,32 @@ const (
ResponseCategoryCertificateRequired
)
-func ResponseCategoryForStatus(status gus.Status) ResponseCategory {
+func ResponseCategoryForStatus(status sr.Status) ResponseCategory {
return ResponseCategory(status / 10)
}
const (
// StatusInput indicates a required query parameter at the requested URL.
- StatusInput gus.Status = gus.Status(ResponseCategoryInput) + iota
+ StatusInput sr.Status = sr.Status(ResponseCategoryInput) + iota
// StatusSensitiveInput indicates a sensitive query parameter is required.
StatusSensitiveInput
)
const (
// StatusSuccess is a successful response.
- StatusSuccess = gus.Status(ResponseCategorySuccess) + iota
+ StatusSuccess = sr.Status(ResponseCategorySuccess) + iota
)
const (
// StatusTemporaryRedirect indicates a temporary redirect to another URL.
- StatusTemporaryRedirect = gus.Status(ResponseCategoryRedirect) + iota
+ StatusTemporaryRedirect = sr.Status(ResponseCategoryRedirect) + iota
// StatusPermanentRedirect indicates that the resource should always be requested at the new URL.
StatusPermanentRedirect
)
const (
// StatusTemporaryFailure indicates that the request failed and there is no response body.
- StatusTemporaryFailure = gus.Status(ResponseCategoryTemporaryFailure) + iota
+ StatusTemporaryFailure = sr.Status(ResponseCategoryTemporaryFailure) + iota
// StatusServerUnavailable occurs when the server is unavailable due to overload or maintenance.
StatusServerUnavailable
// StatusCGIError is the result of a failure of a CGI script.
@@ -84,7 +84,7 @@ const (
const (
// StatusPermanentFailure is a server failure which should be expected to continue indefinitely.
- StatusPermanentFailure = gus.Status(ResponseCategoryPermanentFailure) + iota
+ StatusPermanentFailure = sr.Status(ResponseCategoryPermanentFailure) + iota
// StatusNotFound means the resource doesn't exist but it may in the future.
StatusNotFound
// StatusGone occurs when a resource will not be available any longer.
@@ -92,12 +92,12 @@ const (
// StatusProxyRequestRefused means the server is unwilling to act as a proxy for the resource.
StatusProxyRequestRefused
// StatusBadRequest indicates that the request was malformed somehow.
- StatusBadRequest = gus.Status(ResponseCategoryPermanentFailure) + 9
+ StatusBadRequest = sr.Status(ResponseCategoryPermanentFailure) + 9
)
const (
// StatusClientCertificateRequired is returned when a certificate was required but not provided.
- StatusClientCertificateRequired = gus.Status(ResponseCategoryCertificateRequired) + iota
+ StatusClientCertificateRequired = sr.Status(ResponseCategoryCertificateRequired) + iota
// StatusCertificateNotAuthorized means the certificate doesn't grant access to the requested resource.
StatusCertificateNotAuthorized
// StatusCertificateNotValid means the provided client certificate is invalid.
@@ -105,24 +105,24 @@ const (
)
// Input builds an input-prompting response.
-func Input(prompt string) *gus.Response {
- return &gus.Response{
+func Input(prompt string) *sr.Response {
+ return &sr.Response{
Status: StatusInput,
Meta: prompt,
}
}
// SensitiveInput builds a password-prompting response.
-func SensitiveInput(prompt string) *gus.Response {
- return &gus.Response{
+func SensitiveInput(prompt string) *sr.Response {
+ return &sr.Response{
Status: StatusSensitiveInput,
Meta: prompt,
}
}
// Success builds a success response with resource body.
-func Success(mediatype string, body io.Reader) *gus.Response {
- return &gus.Response{
+func Success(mediatype string, body io.Reader) *sr.Response {
+ return &sr.Response{
Status: StatusSuccess,
Meta: mediatype,
Body: body,
@@ -130,120 +130,120 @@ func Success(mediatype string, body io.Reader) *gus.Response {
}
// Redirect builds a redirect response.
-func Redirect(url string) *gus.Response {
- return &gus.Response{
+func Redirect(url string) *sr.Response {
+ return &sr.Response{
Status: StatusTemporaryRedirect,
Meta: url,
}
}
// PermanentRedirect builds a response with a permanent redirect.
-func PermanentRedirect(url string) *gus.Response {
- return &gus.Response{
+func PermanentRedirect(url string) *sr.Response {
+ return &sr.Response{
Status: StatusPermanentRedirect,
Meta: url,
}
}
// Failure builds a temporary failure response from an error.
-func Failure(err error) *gus.Response {
- return &gus.Response{
+func Failure(err error) *sr.Response {
+ return &sr.Response{
Status: StatusTemporaryFailure,
Meta: err.Error(),
}
}
// Unavailable build a "server unavailable" response.
-func Unavailable(msg string) *gus.Response {
- return &gus.Response{
+func Unavailable(msg string) *sr.Response {
+ return &sr.Response{
Status: StatusServerUnavailable,
Meta: msg,
}
}
// CGIError builds a "cgi error" response.
-func CGIError(err string) *gus.Response {
- return &gus.Response{
+func CGIError(err string) *sr.Response {
+ return &sr.Response{
Status: StatusCGIError,
Meta: err,
}
}
// ProxyError builds a proxy error response.
-func ProxyError(msg string) *gus.Response {
- return &gus.Response{
+func ProxyError(msg string) *sr.Response {
+ return &sr.Response{
Status: StatusProxyError,
Meta: msg,
}
}
// SlowDown builds a "slow down" response with the number of seconds until the resource is available.
-func SlowDown(seconds int) *gus.Response {
- return &gus.Response{
+func SlowDown(seconds int) *sr.Response {
+ return &sr.Response{
Status: StatusSlowDown,
Meta: strconv.Itoa(seconds),
}
}
// PermanentFailure builds a "permanent failure" from an error.
-func PermanentFailure(err error) *gus.Response {
- return &gus.Response{
+func PermanentFailure(err error) *sr.Response {
+ return &sr.Response{
Status: StatusPermanentFailure,
Meta: err.Error(),
}
}
// NotFound builds a "resource not found" response.
-func NotFound(msg string) *gus.Response {
- return &gus.Response{
+func NotFound(msg string) *sr.Response {
+ return &sr.Response{
Status: StatusNotFound,
Meta: msg,
}
}
// Gone builds a "resource gone" response.
-func Gone(msg string) *gus.Response {
- return &gus.Response{
+func Gone(msg string) *sr.Response {
+ return &sr.Response{
Status: StatusGone,
Meta: msg,
}
}
// RefuseProxy builds a "proxy request refused" response.
-func RefuseProxy(msg string) *gus.Response {
- return &gus.Response{
+func RefuseProxy(msg string) *sr.Response {
+ return &sr.Response{
Status: StatusProxyRequestRefused,
Meta: msg,
}
}
// BadRequest builds a "bad request" response.
-func BadRequest(msg string) *gus.Response {
- return &gus.Response{
+func BadRequest(msg string) *sr.Response {
+ return &sr.Response{
Status: StatusBadRequest,
Meta: msg,
}
}
// RequireCert builds a "client certificate required" response.
-func RequireCert(msg string) *gus.Response {
- return &gus.Response{
+func RequireCert(msg string) *sr.Response {
+ return &sr.Response{
Status: StatusClientCertificateRequired,
Meta: msg,
}
}
// CertAuthFailure builds a "certificate not authorized" response.
-func CertAuthFailure(msg string) *gus.Response {
- return &gus.Response{
+func CertAuthFailure(msg string) *sr.Response {
+ return &sr.Response{
Status: StatusCertificateNotAuthorized,
Meta: msg,
}
}
// CertInvalid builds a "client certificate not valid" response.
-func CertInvalid(msg string) *gus.Response {
- return &gus.Response{
+func CertInvalid(msg string) *sr.Response {
+ return &sr.Response{
Status: StatusCertificateNotValid,
Meta: msg,
}
@@ -258,7 +258,7 @@ var InvalidResponseHeaderLine = errors.New("Invalid response header line.")
// ParseResponse parses a complete gemini response from a reader.
//
// The reader must contain only one gemini response.
-func ParseResponse(rdr io.Reader) (*gus.Response, error) {
+func ParseResponse(rdr io.Reader) (*sr.Response, error) {
bufrdr := bufio.NewReader(rdr)
hdrLine, err := bufrdr.ReadBytes('\n')
@@ -278,14 +278,14 @@ func ParseResponse(rdr io.Reader) (*gus.Response, error) {
return nil, InvalidResponseHeaderLine
}
- return &gus.Response{
- Status: gus.Status(status),
+ return &sr.Response{
+ Status: sr.Status(status),
Meta: string(hdrLine[3:]),
Body: bufrdr,
}, nil
}
-func NewResponseReader(response *gus.Response) gus.ResponseReader {
+func NewResponseReader(response *sr.Response) sr.ResponseReader {
return &responseReader{
Response: response,
once: &sync.Once{},
@@ -293,7 +293,7 @@ func NewResponseReader(response *gus.Response) gus.ResponseReader {
}
type responseReader struct {
- *gus.Response
+ *sr.Response
reader io.Reader
once *sync.Once
}