httpx: Add new redirect
This commit is contained in:
parent
41d41035e3
commit
8e2d2cce3e
5 changed files with 123 additions and 35 deletions
|
|
@ -1,6 +1,25 @@
|
|||
package httpx
|
||||
|
||||
import "errors"
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// ErrNotFound should be returned from any httpx error to indicate that the item was not found
|
||||
var ErrNotFound = errors.New("httpx: Error 404")
|
||||
// Response represents a response to an http request.
|
||||
type Response struct {
|
||||
ContentType string // defaults to text/plain
|
||||
Body []byte
|
||||
StatusCode int // defaults to [http.StatusOK]
|
||||
}
|
||||
|
||||
func (response Response) ServerHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
if response.ContentType == "" {
|
||||
response.ContentType = "text/plain"
|
||||
}
|
||||
w.Header().Set("Content-Type", response.ContentType)
|
||||
|
||||
if response.StatusCode <= 0 {
|
||||
response.StatusCode = http.StatusOK
|
||||
}
|
||||
w.WriteHeader(response.StatusCode)
|
||||
w.Write(response.Body)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue