summaryrefslogtreecommitdiff
path: root/gemini/response.go
diff options
context:
space:
mode:
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 9d4ede1..13f493a 100644
--- a/gemini/response.go
+++ b/gemini/response.go
@@ -8,7 +8,7 @@ import (
"strconv"
"sync"
- sr "tildegit.org/tjp/sliderule"
+ "tildegit.org/tjp/sliderule/internal/types"
)
// ResponseCategory represents the various types of gemini responses.
@@ -43,32 +43,32 @@ const (
ResponseCategoryCertificateRequired
)
-func ResponseCategoryForStatus(status sr.Status) ResponseCategory {
+func ResponseCategoryForStatus(status types.Status) ResponseCategory {
return ResponseCategory(status / 10)
}
const (
// StatusInput indicates a required query parameter at the requested URL.
- StatusInput sr.Status = sr.Status(ResponseCategoryInput) + iota
+ StatusInput types.Status = types.Status(ResponseCategoryInput) + iota
// StatusSensitiveInput indicates a sensitive query parameter is required.
StatusSensitiveInput
)
const (
// StatusSuccess is a successful response.
- StatusSuccess = sr.Status(ResponseCategorySuccess) + iota
+ StatusSuccess = types.Status(ResponseCategorySuccess) + iota
)
const (
// StatusTemporaryRedirect indicates a temporary redirect to another URL.
- StatusTemporaryRedirect = sr.Status(ResponseCategoryRedirect) + iota
+ StatusTemporaryRedirect = types.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 = sr.Status(ResponseCategoryTemporaryFailure) + iota
+ StatusTemporaryFailure = types.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 = sr.Status(ResponseCategoryPermanentFailure) + iota
+ StatusPermanentFailure = types.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 = sr.Status(ResponseCategoryPermanentFailure) + 9
+ StatusBadRequest = types.Status(ResponseCategoryPermanentFailure) + 9
)
const (
// StatusClientCertificateRequired is returned when a certificate was required but not provided.
- StatusClientCertificateRequired = sr.Status(ResponseCategoryCertificateRequired) + iota
+ StatusClientCertificateRequired = types.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) *sr.Response {
- return &sr.Response{
+func Input(prompt string) *types.Response {
+ return &types.Response{
Status: StatusInput,
Meta: prompt,
}
}
// SensitiveInput builds a password-prompting response.
-func SensitiveInput(prompt string) *sr.Response {
- return &sr.Response{
+func SensitiveInput(prompt string) *types.Response {
+ return &types.Response{
Status: StatusSensitiveInput,
Meta: prompt,
}
}
// Success builds a success response with resource body.
-func Success(mediatype string, body io.Reader) *sr.Response {
- return &sr.Response{
+func Success(mediatype string, body io.Reader) *types.Response {
+ return &types.Response{
Status: StatusSuccess,
Meta: mediatype,
Body: body,
@@ -130,120 +130,120 @@ func Success(mediatype string, body io.Reader) *sr.Response {
}
// Redirect builds a redirect response.
-func Redirect(url string) *sr.Response {
- return &sr.Response{
+func Redirect(url string) *types.Response {
+ return &types.Response{
Status: StatusTemporaryRedirect,
Meta: url,
}
}
// PermanentRedirect builds a response with a permanent redirect.
-func PermanentRedirect(url string) *sr.Response {
- return &sr.Response{
+func PermanentRedirect(url string) *types.Response {
+ return &types.Response{
Status: StatusPermanentRedirect,
Meta: url,
}
}
// Failure builds a temporary failure response from an error.
-func Failure(err error) *sr.Response {
- return &sr.Response{
+func Failure(err error) *types.Response {
+ return &types.Response{
Status: StatusTemporaryFailure,
Meta: err.Error(),
}
}
// Unavailable build a "server unavailable" response.
-func Unavailable(msg string) *sr.Response {
- return &sr.Response{
+func Unavailable(msg string) *types.Response {
+ return &types.Response{
Status: StatusServerUnavailable,
Meta: msg,
}
}
// CGIError builds a "cgi error" response.
-func CGIError(err string) *sr.Response {
- return &sr.Response{
+func CGIError(err string) *types.Response {
+ return &types.Response{
Status: StatusCGIError,
Meta: err,
}
}
// ProxyError builds a proxy error response.
-func ProxyError(msg string) *sr.Response {
- return &sr.Response{
+func ProxyError(msg string) *types.Response {
+ return &types.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) *sr.Response {
- return &sr.Response{
+func SlowDown(seconds int) *types.Response {
+ return &types.Response{
Status: StatusSlowDown,
Meta: strconv.Itoa(seconds),
}
}
// PermanentFailure builds a "permanent failure" from an error.
-func PermanentFailure(err error) *sr.Response {
- return &sr.Response{
+func PermanentFailure(err error) *types.Response {
+ return &types.Response{
Status: StatusPermanentFailure,
Meta: err.Error(),
}
}
// NotFound builds a "resource not found" response.
-func NotFound(msg string) *sr.Response {
- return &sr.Response{
+func NotFound(msg string) *types.Response {
+ return &types.Response{
Status: StatusNotFound,
Meta: msg,
}
}
// Gone builds a "resource gone" response.
-func Gone(msg string) *sr.Response {
- return &sr.Response{
+func Gone(msg string) *types.Response {
+ return &types.Response{
Status: StatusGone,
Meta: msg,
}
}
// RefuseProxy builds a "proxy request refused" response.
-func RefuseProxy(msg string) *sr.Response {
- return &sr.Response{
+func RefuseProxy(msg string) *types.Response {
+ return &types.Response{
Status: StatusProxyRequestRefused,
Meta: msg,
}
}
// BadRequest builds a "bad request" response.
-func BadRequest(msg string) *sr.Response {
- return &sr.Response{
+func BadRequest(msg string) *types.Response {
+ return &types.Response{
Status: StatusBadRequest,
Meta: msg,
}
}
// RequireCert builds a "client certificate required" response.
-func RequireCert(msg string) *sr.Response {
- return &sr.Response{
+func RequireCert(msg string) *types.Response {
+ return &types.Response{
Status: StatusClientCertificateRequired,
Meta: msg,
}
}
// CertAuthFailure builds a "certificate not authorized" response.
-func CertAuthFailure(msg string) *sr.Response {
- return &sr.Response{
+func CertAuthFailure(msg string) *types.Response {
+ return &types.Response{
Status: StatusCertificateNotAuthorized,
Meta: msg,
}
}
// CertInvalid builds a "client certificate not valid" response.
-func CertInvalid(msg string) *sr.Response {
- return &sr.Response{
+func CertInvalid(msg string) *types.Response {
+ return &types.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) (*sr.Response, error) {
+func ParseResponse(rdr io.Reader) (*types.Response, error) {
bufrdr := bufio.NewReader(rdr)
hdrLine, err := bufrdr.ReadBytes('\n')
@@ -278,14 +278,14 @@ func ParseResponse(rdr io.Reader) (*sr.Response, error) {
return nil, InvalidResponseHeaderLine
}
- return &sr.Response{
- Status: sr.Status(status),
+ return &types.Response{
+ Status: types.Status(status),
Meta: string(hdrLine[3:]),
Body: bufrdr,
}, nil
}
-func NewResponseReader(response *sr.Response) sr.ResponseReader {
+func NewResponseReader(response *types.Response) types.ResponseReader {
return &responseReader{
Response: response,
once: &sync.Once{},
@@ -293,7 +293,7 @@ func NewResponseReader(response *sr.Response) sr.ResponseReader {
}
type responseReader struct {
- *sr.Response
+ *types.Response
reader io.Reader
once *sync.Once
}