StaticResponse implements a simple responder for static responses.
| 87 | |
| 88 | // StaticResponse implements a simple responder for static responses. |
| 89 | type StaticResponse struct { |
| 90 | // The HTTP status code to respond with. Can be an integer or, |
| 91 | // if needing to use a placeholder, a string. |
| 92 | // |
| 93 | // If the status code is 103 (Early Hints), the response headers |
| 94 | // will be written to the client immediately, the body will be |
| 95 | // ignored, and the next handler will be invoked. This behavior |
| 96 | // is EXPERIMENTAL while RFC 8297 is a draft, and may be changed |
| 97 | // or removed. |
| 98 | StatusCode WeakString `json:"status_code,omitempty"` |
| 99 | |
| 100 | // Header fields to set on the response; overwrites any existing |
| 101 | // header fields of the same names after normalization. |
| 102 | Headers http.Header `json:"headers,omitempty"` |
| 103 | |
| 104 | // The response body. If non-empty, the Content-Type header may |
| 105 | // be added automatically if it is not explicitly configured nor |
| 106 | // already set on the response; the default value is |
| 107 | // "text/plain; charset=utf-8" unless the body is a valid JSON object |
| 108 | // or array, in which case the value will be "application/json". |
| 109 | // Other than those common special cases the Content-Type header |
| 110 | // should be set explicitly if it is desired because MIME sniffing |
| 111 | // is disabled for safety. |
| 112 | Body string `json:"body,omitempty"` |
| 113 | |
| 114 | // If true, the server will close the client's connection |
| 115 | // after writing the response. |
| 116 | Close bool `json:"close,omitempty"` |
| 117 | |
| 118 | // Immediately and forcefully closes the connection without |
| 119 | // writing a response. Interrupts any other HTTP streams on |
| 120 | // the same connection. |
| 121 | Abort bool `json:"abort,omitempty"` |
| 122 | } |
| 123 | |
| 124 | // CaddyModule returns the Caddy module information. |
| 125 | func (StaticResponse) CaddyModule() caddy.ModuleInfo { |
nothing calls this directly
no outgoing calls
no test coverage detected