basic_http_interceptor library

Lightweight, pluggable HTTP interceptors for logging, default headers, functional hooks, proxy configurations, and request timeout abortion.

Classes

Abortable
An HTTP request that can be aborted before it completes.
AbortableMultipartRequest
A MultipartRequest which supports abortion using abortTrigger.
AbortableRequest
A Request which supports abortion using abortTrigger.
AbortableStreamedRequest
A StreamedRequest which supports abortion using abortTrigger.
BaseClient
The abstract base class for an HTTP client.
BaseRequest
The base class for HTTP requests.
BaseResponse
The base class for HTTP responses.
BaseResponseWithUrl
A BaseResponse with a url field.
ByteStream
A stream of chunks of bytes representing a single piece of data.
Client
The interface for HTTP clients that take care of maintaining persistent connections across multiple requests to the same server.
InterceptedClient
Class to be used by the user to set up a new http.Client with interceptor support.
InterceptedHttp
Class to be used by the user as a replacement for 'http' with interceptor support.
InterceptorContract
Interceptor interface to create custom Interceptor for http. Extend this class and override the functions that you want to intercept.
InterceptorHeader
An interceptor that attaches a predefined set of HTTP headers to every outgoing request.
InterceptorHook
An interceptor that transforms requests and responses using custom callback functions.
InterceptorLogger
An interceptor that logs HTTP requests and responses using the logging package.
InterceptorTimeout
An interceptor that enforces a physical connection timeout on HTTP requests using Abortable.
MediaType
A class representing an HTTP media type, as used in Accept and Content-Type headers.
MethodSwitchingClient
A client wrapper that dynamically routes requests between HTTP clients based on request type and content.
MultipartFile
A file to be uploaded as part of a MultipartRequest.
MultipartRequest
A multipart/form-data request.
Request
An HTTP request where the entire request body is known in advance.
Response
An HTTP response where the entire response body is known in advance.
RetryPolicy
Defines the behavior for retrying requests.
StreamedRequest
An HTTP request where the request body is sent asynchronously after the connection has been established and the headers have been sent.
StreamedResponse
An HTTP response where the response body is received asynchronously after the headers have been received.

Enums

HttpMethod
Enum representation of all available HTTP methods.

Extensions

AddParameters on Uri
Extends Uri to allow adding parameters to already created intstances
BaseRequestCopyWith on BaseRequest
Extends BaseRequest to provide copied instances.
BaseResponseCopyWith on BaseResponse
HeadersWithSplitValues on BaseResponse
MethodToString on HttpMethod
Extends HttpMethod to provide a String representation.
MultipartRequestCopyWith on MultipartRequest
Extends MultipartRequest to provide copied instances.
RequestCopyWith on Request
Extends Request to provide copied instances.
ResponseCopyWith on Response
Extends Response to provide copied instances.
StreamedRequestCopyWith on StreamedRequest
Extends StreamedRequest to provide copied instances.
StreamedResponseCopyWith on StreamedResponse
Extends StreamedResponse to provide copied instances.
StringToMethod on HttpMethod
Extends HttpMethod to be initialized from a String value.
ToURI on String
Extends String to provide URI compatibility.

Functions

buildUrlString(String url, Map<String, dynamic>? parameters) String
Takes a string and appends parameters as query parameters of url.
delete(Uri url, {Map<String, String>? headers, Object? body, Encoding? encoding}) Future<Response>
Sends an HTTP DELETE request with the given headers to the given URL.
get(Uri url, {Map<String, String>? headers}) Future<Response>
Sends an HTTP GET request with the given headers to the given URL.
Sends an HTTP HEAD request with the given headers to the given URL.
inferAuthorizationHeaderValue(String authorization) String
Infers and adds an authorization scheme to an untyped authorization token.
interceptedClient({required List<InterceptorContract> interceptors, Map<String, String> proxy = const {}}) InterceptedClient
Creates an InterceptedClient configured with the given interceptors and optional proxy settings.
isBase64Credentials(String base64String) bool
Validates whether base64String decodes to a username:password pair.
isJwt(String token) bool
Validates whether token has the structural format of a JSON Web Token.
normalizeAuthorizationHeaders(Map<String, String> headers) Map<String, String>
Returns a copy of headers with its Authorization header normalized.
patch(Uri url, {Map<String, String>? headers, Object? body, Encoding? encoding}) Future<Response>
Sends an HTTP PATCH request with the given headers and body to the given URL.
post(Uri url, {Map<String, String>? headers, Object? body, Encoding? encoding}) Future<Response>
Sends an HTTP POST request with the given headers and body to the given URL.
proxyClient({Map<String, String> headers = const {}, Map<String, String> proxy = const {}, List<InterceptorContract> interceptors = const [], Duration? timeout, Logger? logger}) InterceptedClient
Creates an HTTP client configured with custom interceptors, request headers, a request timeout, and a proxy.
put(Uri url, {Map<String, String>? headers, Object? body, Encoding? encoding}) Future<Response>
Sends an HTTP PUT request with the given headers and body to the given URL.
read(Uri url, {Map<String, String>? headers}) Future<String>
Sends an HTTP GET request with the given headers to the given URL and returns a Future that completes to the body of the response as a String.
readBytes(Uri url, {Map<String, String>? headers}) Future<Uint8List>
Sends an HTTP GET request with the given headers to the given URL and returns a Future that completes to the body of the response as a list of bytes.
runWithClient<R>(R body(), Client clientFactory(), {ZoneSpecification? zoneSpecification}) → R
Runs body in its own Zone with the Client returned by clientFactory set as the default Client.

Typedefs

TimeoutCallback = void Function(BaseRequest request)

Exceptions / Errors

ClientException
An exception caused by an error in a pkg/http client.
HttpInterceptorException
RequestAbortedException
Thrown when an HTTP request is aborted.