Summary
BrowserClient currently maps its withCredentials option to only two browser fetch credentials modes:
credentials: withCredentials ? 'include' : 'same-origin',
This makes it possible to use:
However, the third valid fetch credentials mode, omit, is currently not configurable through the public BrowserClient API.
It would be useful if BrowserClient allowed callers to explicitly configure the credentials mode used for browser requests.
Use case
In some Flutter Web applications, requests must be sent without browser credentials, even for same-origin requests. This means cookies, client certificates, and HTTP authentication information should not be included by the browser.
The desired browser fetch configuration is:
At the moment, the only way to achieve this behavior with package:http appears to be forking or copying the BrowserClient implementation and changing the request initialization manually.
Current behavior
When withCredentials is false, BrowserClient uses:
credentials: 'same-origin',
When withCredentials is true, BrowserClient uses:
There is no public API to select:
Expected behavior
BrowserClient should expose a way to configure all credentials modes supported by the browser fetch API:
This would avoid the need for package forks when applications require requests to be sent without browser credentials.
Possible API
One possible approach would be to introduce an explicit credentials mode enum:
enum BrowserCredentialsMode {
omit,
sameOrigin,
include,
}
And allow it to be configured on BrowserClient:
final client = BrowserClient(
credentialsMode: BrowserCredentialsMode.omit,
);
For backward compatibility, the default could remain equivalent to the current behavior:
BrowserCredentialsMode.sameOrigin
The existing withCredentials API could either be kept as a convenience option or deprecated in favor of the more explicit credentials mode.
Why withCredentials is not expressive enough
The current boolean API can only represent two states:
false -> same-origin
true -> include
But the browser supports three distinct credentials modes:
Therefore, a boolean does not fully represent the underlying browser behavior.
Workaround
The current workaround is to fork or copy BrowserClient and change the RequestInit configuration manually:
This works technically, but it is difficult to maintain because the fork has to track upstream changes in package:http.
Benefits
Adding this option would:
- expose the full browser
fetch credentials behavior
- remove the need for forks for this use case
- make credentials handling explicit at the call site
- improve compatibility with applications that have strict cookie or authentication requirements
- keep the existing default behavior unchanged
Proposed outcome
Please consider adding support for configuring the browser fetch credentials mode in BrowserClient, including support for omit.
Summary
BrowserClientcurrently maps itswithCredentialsoption to only two browserfetchcredentials modes:This makes it possible to use:
includesame-originHowever, the third valid
fetchcredentials mode,omit, is currently not configurable through the publicBrowserClientAPI.It would be useful if
BrowserClientallowed callers to explicitly configure the credentials mode used for browser requests.Use case
In some Flutter Web applications, requests must be sent without browser credentials, even for same-origin requests. This means cookies, client certificates, and HTTP authentication information should not be included by the browser.
The desired browser
fetchconfiguration is:At the moment, the only way to achieve this behavior with
package:httpappears to be forking or copying theBrowserClientimplementation and changing the request initialization manually.Current behavior
When
withCredentialsisfalse,BrowserClientuses:When
withCredentialsistrue,BrowserClientuses:There is no public API to select:
Expected behavior
BrowserClientshould expose a way to configure all credentials modes supported by the browserfetchAPI:omitsame-originincludeThis would avoid the need for package forks when applications require requests to be sent without browser credentials.
Possible API
One possible approach would be to introduce an explicit credentials mode enum:
And allow it to be configured on
BrowserClient:For backward compatibility, the default could remain equivalent to the current behavior:
BrowserCredentialsMode.sameOriginThe existing
withCredentialsAPI could either be kept as a convenience option or deprecated in favor of the more explicit credentials mode.Why
withCredentialsis not expressive enoughThe current boolean API can only represent two states:
But the browser supports three distinct credentials modes:
Therefore, a boolean does not fully represent the underlying browser behavior.
Workaround
The current workaround is to fork or copy
BrowserClientand change theRequestInitconfiguration manually:This works technically, but it is difficult to maintain because the fork has to track upstream changes in
package:http.Benefits
Adding this option would:
fetchcredentials behaviorProposed outcome
Please consider adding support for configuring the browser
fetchcredentials mode inBrowserClient, including support foromit.