From b2ff86d213128bb6f9ec9fa017ee4d566c77a397 Mon Sep 17 00:00:00 2001 From: tjp Date: Wed, 10 Jan 2024 11:07:17 -0700 Subject: function to get names of gemini response codes --- gemini/response.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/gemini/response.go b/gemini/response.go index b3e53aa..ec4ac2b 100644 --- a/gemini/response.go +++ b/gemini/response.go @@ -4,6 +4,7 @@ import ( "bufio" "bytes" "errors" + "fmt" "io" "strconv" "sync" @@ -249,6 +250,49 @@ func CertInvalid(msg string) *types.Response { } } +func StatusName(status types.Status) string { + switch status { + case StatusInput: + return "StatusInput" + case StatusSensitiveInput: + return "StatusSensitiveInput" + case StatusSuccess: + return "StatusSuccess" + case StatusTemporaryRedirect: + return "StatusTemporaryRedirect" + case StatusPermanentRedirect: + return "StatusPermanentRedirect" + case StatusTemporaryFailure: + return "StatusTemporaryFailure" + case StatusServerUnavailable: + return "StatusServerUnavailable" + case StatusCGIError: + return "StatusCGIError" + case StatusProxyError: + return "StatusProxyError" + case StatusSlowDown: + return "StatusSlowDown" + case StatusPermanentFailure: + return "StatusPermanentFailure" + case StatusNotFound: + return "StatusNotFound" + case StatusGone: + return "StatusGone" + case StatusProxyRequestRefused: + return "StatusProxyRequestRefused" + case StatusBadRequest: + return "StatusBadRequest" + case StatusClientCertificateRequired: + return "StatusClientCertificateRequired" + case StatusCertificateNotAuthorized: + return "StatusCertificateNotAuthorized" + case StatusCertificateNotValid: + return "StatusCertificateNotValid" + default: + return fmt.Sprintf("Unknown (%d)", status) + } +} + // InvalidResponseLineEnding indicates that a gemini response header didn't end with "\r\n". var InvalidResponseLineEnding = errors.New("Invalid response line ending.") -- cgit v1.2.3