Documentation
¶
Overview ¶
Package httphandler provides a basic net/http http.Handler implementation that resolves URLs.
The handler expects a ?url=URL_TO_RESOLVE query parameter, and responds with a JSON object containing the resolved URL and the resolved title:
$ curl -s localhost:8080/resolve?url=https://nyti.ms/2FVHq9v | jq .
{
"given_url": "https://nyti.ms/2FVHq9v",
"resolved_url": "https://www.nytimes.com/tips",
"title": "Tips - The New York Times"
}
If an error occurs during resolution, the response status code will be 203 Non-Authoritative Information (to indicate partial response), an additional error field will be added, and a partial result will be returned, including the canonicalized and potentially partially-resolved URL:
$ curl -s localhost:8080/resolve?url=https://i-do-not-exist.xyz?utm_tag=tracking-code | jq .
{
"given_url": "https://i-do-not-exist.xyz?utm_tag=tracking-code",
"resolved_url": "https://i-do-not-exist.xyz",
"title": "",
"error": "resolve error"
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidURL = errors.New("invalid arg url") ErrMissingURL = errors.New("missing arg url") ErrRequestTimeout = errors.New("request timeout") ErrResolveError = errors.New("resolve error") ErrUnsafeURL = errors.New("unsafe URL") )
Errors that might be returned by the HTTP handler.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is an HTTP request handler that can resolve URLs.
type ResolveResponse ¶
type ResolveResponse struct {
GivenURL string `json:"given_url"`
ResolvedURL string `json:"resolved_url"`
Title string `json:"title"`
IntermediateURLs []string `json:"intermediate_urls"`
Error string `json:"error,omitempty"`
}
ResolveResponse defines the HTTP handler's response structure.