Documentation
¶
Overview ¶
Package httpapi sends authenticated HTTP requests and streams generated media.
Index ¶
- Constants
- func DownloadInputMedia(ctx context.Context, mediaInputs []media.Input) ([]media.Input, error)
- func Fetch(ctx context.Context, endpoint string, credential AuthCredential, ...) (artifact.Media, error)
- func GetAuth(ctx context.Context, endpoint string, credential AuthCredential, ...) (status int, respBody []byte, err error)
- func Poll(ctx context.Context, pace, pollBudget time.Duration, poller jobPoll) error
- func PostJSON(ctx context.Context, endpoint string, credential AuthCredential, body any, ...) (status int, respBody []byte, err error)
- func ResolveInputMediaTypes(ctx context.Context, mediaInputs []media.Input) ([]media.Input, error)
- func SendBody(ctx context.Context, endpoint string, credential AuthCredential, ...) (status int, respBody []byte, err error)
- type AuthCredential
Constants ¶
const ( ByteLimitForm = "limit %d bytes" StatusExcerptForm = "%s: status %d: %s" TimeoutAfterForm = "after %s" )
The internal/httpapi section of the copy catalog, one constant per entry.
Variables ¶
This section is empty.
Functions ¶
func DownloadInputMedia ¶
DownloadInputMedia downloads URL inputs without credentials into a copied media slice. It preserves source order and leaves format compatibility to the receiving provider. On failure it returns completed downloads and untouched remaining inputs without mutating the caller's slice.
func Fetch ¶
func Fetch(ctx context.Context, endpoint string, credential AuthCredential, fallbackExt string, record *metadata.Record) (artifact.Media, error)
Fetch streams generated media into a temporary file that the caller owns. On failure it removes that file and returns no media. A nonnil record retains received bytes.
func GetAuth ¶
func GetAuth(ctx context.Context, endpoint string, credential AuthCredential, responseType string, record *metadata.Record) (status int, respBody []byte, err error)
GetAuth retrieves an endpoint with the credential and returns its status and bounded body. A nonnil record captures the transaction; responseType labels the response as a poll or direct retrieval.
func Poll ¶
Poll checks a job at fixed intervals until it completes, the context ends, or the polling budget expires. The caller may read its poller's completed result only after Poll succeeds.
func PostJSON ¶
func PostJSON(ctx context.Context, endpoint string, credential AuthCredential, body any, record *metadata.Record) (status int, respBody []byte, err error)
PostJSON sends body as JSON and returns the response status and body. When record is nonnil, it captures the actual request and full bounded response.
func ResolveInputMediaTypes ¶
ResolveInputMediaTypes returns copies with unresolved remote media identified. It tries HTTP metadata, then a bounded content sample, without provider credentials. Source URLs, existing metadata, bytes, and frame information remain unchanged. A source that cannot be read or identified returns a classified input error.
func SendBody ¶
func SendBody(ctx context.Context, endpoint string, credential AuthCredential, contentType string, body []byte, record *metadata.Record) (status int, respBody []byte, err error)
SendBody posts a prepared body and returns the response status and bounded body. A nonnil record captures the request, response, and any transfer failure.
Types ¶
type AuthCredential ¶
type AuthCredential struct{ HeaderName, Value string }
AuthCredential contains an HTTP header credential.
- HeaderName: the request header that carries the credential
- Value: the complete credential header value
func Bearer ¶
func Bearer(apiKey string) AuthCredential
Bearer returns an Authorization header credential containing an API key.
func CredentialForURL ¶
func CredentialForURL(candidateURL, apiBase string, credential AuthCredential) AuthCredential
CredentialForURL returns the credential only when the candidate and API base have the same origin. An invalid or nonabsolute candidate, or an origin mismatch, receives no credential.
func HeaderCred ¶
func HeaderCred(header, apiKey string) AuthCredential
HeaderCred returns a credential containing a header name and API key.