diff --git a/CHANGELOG.md b/CHANGELOG.md index 3989e70..5ccdf69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.9.8: Message code cleanup + +This release cleans up the message codes being emitted. + ## 0.9.7: Bugfixing validation This release fixes a validation bug introduced in the previous version where TLS parameters were validated even if the URL didn't point to a `https://` URL. diff --git a/CODES.md b/CODES.md index f2e97d9..174c46c 100644 --- a/CODES.md +++ b/CODES.md @@ -1,10 +1,12 @@ -# Message/error codes +# Message / error codes | Code | Explanation | -| `HTTP_CLIENT_CONNECTION_FAILED` | Sending a HTTP request failed for reasons outside of ContainerSSH | -| `HTTP_CLIENT_DECODE_FAILED` | ContainerSSH failed to decode the JSON response after sending a request. Check if the HTTP server is misbehaving. | -| `HTTP_CLIENT_ENCODE_FAILED` | ContainerSSH failed to encode the payload for sending a HTTP request. This is a bug, please file an issue. | -| `HTTP_CLIENT_REDIRECTS_DISABLED` | ContainerSSH is refusing to follow a HTTP redirect received because the `allowRedirects` option is disabled. | -| `HTTP_CLIENT_REDIRECT` | ContainerSSH has received a HTTP redirect from the server. | -| `HTTP_CLIENT_RESPONSE` | ContainerSSH has received a response to a HTTP request sent to a server. | -| `HTTP_CLIENT_REQUEST` | ContainerSSH is sending a HTTP request to a server. | +|------|-------------| +| `HTTP_CLIENT_CONNECTION_FAILED` | This message indicates a connection failure on the network level. | +| `HTTP_CLIENT_DECODE_FAILED` | This message indicates that decoding the JSON response has failed. The status code is set for this code. | +| `HTTP_CLIENT_ENCODE_FAILED` | This message indicates that JSON encoding the request failed. This is usually a bug. | +| `HTTP_CLIENT_REDIRECT` | This message indicates that the server responded with a HTTP redirect. | +| `HTTP_CLIENT_REDIRECTS_DISABLED` | This message indicates that ContainerSSH is not following a HTTP redirect sent by the server. Use the allowRedirects option to allow following HTTP redirects. | +| `HTTP_CLIENT_REQUEST` | This message indicates that a HTTP request is being sent from ContainerSSH | +| `HTTP_CLIENT_RESPONSE` | This message indicates that ContainerSSH received a HTTP response from a server. | + diff --git a/codes.go b/codes.go index f490770..9908a40 100644 --- a/codes.go +++ b/codes.go @@ -1,22 +1,24 @@ package http -const ( - // EFailureEncodeFailed indicates that JSON encoding the request failed. This is usually a bug. - EFailureEncodeFailed = "HTTP_CLIENT_ENCODE_FAILED" - // EFailureConnectionFailed indicates a connection failure on the network level. - EFailureConnectionFailed = "HTTP_CLIENT_CONNECTION_FAILED" - // EFailureDecodeFailed indicates that decoding the JSON response has failed. The status code is set for this - // code. - EFailureDecodeFailed = "HTTP_CLIENT_DECODE_FAILED" - // EClientRedirectsDisabled indicates that ContainerSSH is not following a HTTP redirect sent by the server. - EClientRedirectsDisabled = "HTTP_CLIENT_REDIRECTS_DISABLED" +// This message indicates that JSON encoding the request failed. This is usually a bug. +const EFailureEncodeFailed = "HTTP_CLIENT_ENCODE_FAILED" - // MClientRequest is a message indicating a HTTP request sent from ContainerSSH - MClientRequest = "HTTP_CLIENT_REQUEST" +// This message indicates a connection failure on the network level. +const EFailureConnectionFailed = "HTTP_CLIENT_CONNECTION_FAILED" - // MClientRedirect indicates that the server has sent a HTTP redirect. - MClientRedirect = "HTTP_CLIENT_REDIRECT" +// This message indicates that decoding the JSON response has failed. The status code is set for this +// code. +const EFailureDecodeFailed = "HTTP_CLIENT_DECODE_FAILED" - // MClientResponse is a message indicating receiving a HTTP response to a client request - MClientResponse = "HTTP_CLIENT_RESPONSE" -) +// This message indicates that ContainerSSH is not following a HTTP redirect sent by the server. Use the allowRedirects +// option to allow following HTTP redirects. +const EClientRedirectsDisabled = "HTTP_CLIENT_REDIRECTS_DISABLED" + +// This message indicates that a HTTP request is being sent from ContainerSSH +const MClientRequest = "HTTP_CLIENT_REQUEST" + +// This message indicates that the server responded with a HTTP redirect. +const MClientRedirect = "HTTP_CLIENT_REDIRECT" + +// This message indicates that ContainerSSH received a HTTP response from a server. +const MClientResponse = "HTTP_CLIENT_RESPONSE" diff --git a/codes_doc.go b/codes_doc.go new file mode 100644 index 0000000..87e3b3b --- /dev/null +++ b/codes_doc.go @@ -0,0 +1,3 @@ +package http + +//go:generate containerssh-generate-codes diff --git a/go.mod b/go.mod index aaadb9f..272fd56 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,8 @@ module github.com/containerssh/http go 1.14 require ( - github.com/containerssh/log v0.9.11 - github.com/containerssh/service v0.9.2 + github.com/containerssh/log v0.9.13 + github.com/containerssh/service v0.9.3 github.com/containerssh/structutils v0.9.0 github.com/stretchr/testify v1.7.0 ) diff --git a/go.sum b/go.sum index f089cce..25d03ac 100644 --- a/go.sum +++ b/go.sum @@ -6,10 +6,14 @@ github.com/containerssh/log v0.9.10 h1:c5cYbopsWKX+f5AdDCeMHaRQmkFexpAEgY8MlpLMk github.com/containerssh/log v0.9.10/go.mod h1:NBMzkhOLZ4z45ShSBKQ/Ij6Hqqg15DgOKy6HlSITx0s= github.com/containerssh/log v0.9.11 h1:CLpl9mhxBg4giLZjcZB+FjddYypm2f2x1bCY3iissdA= github.com/containerssh/log v0.9.11/go.mod h1:uVuUPoZsJYi2KoV9+lgPeB/gWuXeUTD3AoVxc4y+tKY= +github.com/containerssh/log v0.9.13 h1:jBSrFaxZNGwkjHU6y/efYI8lyG8KIFR5aOIeOnNzquE= +github.com/containerssh/log v0.9.13/go.mod h1:uVuUPoZsJYi2KoV9+lgPeB/gWuXeUTD3AoVxc4y+tKY= github.com/containerssh/service v0.9.0 h1:JUHqiK12tclq7EWQYGRTfgKKw6fhHs0gxlKWTvVwFlQ= github.com/containerssh/service v0.9.0/go.mod h1:otAKYF1MWy2eB0K7Sk7YQIECQMTHR3yikbyS1UstGpY= github.com/containerssh/service v0.9.2 h1:+EZ7s7sxSme+IosYBR24oNhVlPTz3GJTXBZ0HaSD9rU= github.com/containerssh/service v0.9.2/go.mod h1:nbA2I+GL0vU7ls0JEQKI+QOJfbUjlIDmmUSQqx/G7ro= +github.com/containerssh/service v0.9.3 h1:mYpvZ9zxUrKL8OpBen86heXfGtdUGdtfZ3Y7P605zvQ= +github.com/containerssh/service v0.9.3/go.mod h1:Yeq3hwfM6js9TfpkrQAQhv5IRfurrGEkM+AbFEC9KCE= github.com/containerssh/structutils v0.9.0 h1:pz4xl5ZrPnpdSx7B/ru8Fj3oU3vOtx1jprIuSkm5s7o= github.com/containerssh/structutils v0.9.0/go.mod h1:zirdwNXan3kuTpsJp9Gl3W6VQz0fexqMySqxmfviSjw= github.com/creasty/defaults v1.5.1 h1:j8WexcS3d/t4ZmllX4GEkl4wIB/trOr035ajcLHCISM= diff --git a/server.go b/server.go index 579e0a4..96e230f 100644 --- a/server.go +++ b/server.go @@ -10,6 +10,7 @@ import ( ) // ServerConfiguration is a structure to configure the simple HTTP server by. +//goland:noinspection GoVetStructTag type ServerConfiguration struct { // Listen contains the IP and port to listen on. Listen string `json:"listen" yaml:"listen" default:"0.0.0.0:8080"` @@ -22,9 +23,9 @@ type ServerConfiguration struct { ClientCACert string `json:"clientcacert" yaml:"clientcacert"` // cert is for internal use only. It contains the key and certificate after Validate. - cert *tls.Certificate + cert *tls.Certificate `json:"-" yaml:"-"` // clientCAPool is for internal use only. It contains the client CA pool after Validate. - clientCAPool *x509.CertPool + clientCAPool *x509.CertPool `json:"-" yaml:"-"` } // Validate validates the server configuration.