httphandler

package
v0.0.0-...-96f3e5c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

func New

func New(resolver urlresolver.Interface) *Handler

New creates a new Handler.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL