sleek_http_client 1.5.0
sleek_http_client: ^1.5.0 copied to clipboard
A sleek, pure-Dart HTTP client with connectivity checking, token refresh, multipart support, and structured logging.
Changelog #
1.5.0 #
- BREAKING (behavior) The default
Acceptheader is now deduced fromTinstead of always beingapplication/json:StringandBytesBodyno longer send anyAcceptheader.application/jsonis kept forJsonObject/JsonList(and their nullable variants) and for the undefined types (void,Null,Object?,dynamic, no type argument), so JSON error bodies are still parsed. It applies tosend,sendUriandsendMultipartRequest, and can still be replaced byheadersGetteror by theheadersof a call. A server that answers errors differently withoutAccept: application/json(HTML page or redirect instead of a JSON error, e.g. Laravel validation) is affected: restore the old behavior withheadersGetter: () => {'accept': 'application/json'}.buildAuthorizedHeaders()is unchanged (stillAccept: application/json). - Fixed a header given by
headersGetterwinning over the same header of a call when their names differ by case (e.g.Acceptvsaccept): the call now always wins. - Added
SleekHttpClient.sendUri<T>(): sends a request to a fullUrias is.
1.4.0 #
- Added
SleekHttpClient.abortAll(): aborts every request in flight on the client (retries and a token refresh in progress included), e.g. on logout. Aborted calls throwRequestAbortedException, now re-exported frompackage:http. Requests sent afterwards are not affected. - A timeout now really aborts the underlying request instead of only ceasing to wait for it, so the connection no longer keeps running in the background. The exception thrown is still
ConnectivityException(timeout), and a retry after a timeout starts with a fresh timeout. copyAsNew()keeps the abort link of the original request, so a retry cannot outlive anabortAll().LoggingInterceptorlogs a call cancelled byabortAll()on a🚫line (aborted) instead of a❌line with the exception.
1.3.0 #
- Added per-request
extra:send/sendMultipartRequestacceptextra: {...}, readable in interceptors viarequest.extra[key](newRequestExtraextension onhttp.BaseRequest). It is never sent as an HTTP header, and is copied bycopyAsNew()so it survives a retry. - BREAKING (log format)
LoggingInterceptornow logs one message per call (status icon, duration, bodies on their own lines, host in a[label]) instead of one line for the request and one for the response. The[SleekHttp]prefix is gone and bodies are cut after 500 characters. See the README for the new format. - Added
LoggingInterceptoroptionslayout,labelBuilder,leading,logRequestsandmaxBodyLength. example/main.dart: new scenario showing theLoggingInterceptoroutput.authorityGetteris now optional: the authority can be passed per call instead. AStateErroris thrown when a request is built with neither.sendMultipartRequestnow accepts a per-callauthority, likesend.
1.2.0 #
LoggingInterceptornow also logs exceptions thrown down the chain instead of a response (no internet, timeout, DNS / connection failure, ...) on a❌line, then rethrows them unchanged.- Fixed
send<void>()/send<Null>()/send<Object?>()throwingUnimplementedError(after the request was processed by the server) instead of resolving tonull. - Fixed the timeout not covering the request sending phase (only the body reading): a server that never sent its headers could block a request until the OS-level TCP timeout.
- Fixed a deadlock in
TokenRefreshInterceptorwhen the refresh callback sends its request through the same client after anawait(or behind an asynchronous interceptor): requests toexcludedPathsno longer wait for the in-flight refresh. - An empty success body is now treated like a JSON
nullforJsonObject/JsonList:send<JsonObject?>()resolves tonull,send<JsonObject>()throwsNullResponseBodyException(previously both threw aFormatException).
1.1.0 #
- Added
JsonHttpResponseextension onhttp.Response(isJson,decodeJson<T>(),tryDecodeJson<T>()) so JSON response helpers can be used on anyhttp.Response, not just those produced bySleekHttpClient.
1.0.0 #
- BREAKING Replaced
HttpRetryPolicy/HttpRetryPolicyBuilder/TokenRefreshHandlerandHttpClientLogConfig(logConfig) with a single composableHttpInterceptorchain (SleekHttpClient.interceptors), includingTokenRefreshInterceptorandLoggingInterceptor. - BREAKING
send<T>/sendMultipartRequest<T>now returnTinstead ofT?.T's own nullability drives behavior forJsonObject/JsonList:send<JsonObject>()requires a non-null body and throws the newNullResponseBodyExceptionif the server returns JSONnull, whilesend<JsonObject?>()returnsnullin that case. A malformed body or unexpected JSON shape always throws (FormatException/TypeError), regardless of nullability — it is no longer silently swallowed tonull.
0.1.0 #
- Initial release