Upgrade guide
This guide is designed to help users seamlessly transition from Best HTTP/2 to the new major release (v3.x). If you're updating your package, please read through the relevant sections to ensure a smooth upgrade.
Pre-upgrade Checklist¶
- Backup Your Project: Always create a backup of your entire project before starting the upgrade process. This allows you to revert changes if something goes awry.
- Review Deprecated Features: Check if you're using any features or methods that were marked as deprecated in the last release. Transition away from these first.
Post-upgrade Steps¶
- Update API Calls: If the new version introduced new methods or altered existing ones, update your calls accordingly.
- Test Extensively: After upgrading, test all functionalities in your project that utilize the Best HTTP package to ensure they work as expected.
List of Breaking Changes¶
I have worked hard to enhance features, fix issues, and introduce new capabilities - here's what you need to know:
1. Namespace changes¶
Instead of one big package the new version is split into multiple packages. This packaging change is reflected in how the plugins' namespaces are named. For the Best HTTP package this means that its root namespace is Best.HTTP
instead of BestHTTP
. Upgrading old code might need only an additional dot ('.') in the middle. For a better upgrade experience I kept the most used HTTPRequest and HTTPResponse
classes in the root namespace.
However, other classes are now under different namespaces. Here I'll list a few common classes, their old and new namespaces:
Class | Old Namespace | New Namespace |
---|---|---|
HTTPRequest | BestHTTP | Best.HTTP |
HTTPResponse | BestHTTP | Best.HTTP |
HTTPManager | BestHTTP | Best.HTTP.Shared |
HTTPProxy | BestHTTP | Best.HTTP.Proxies |
LogLevels | BestHTTP.Logger | Best.HTTP.Shared.Logger |
Example
Depending on what IDE you use, deleting old usings first your IDE might help finding the new ones.
2. HTTPRequest changes¶
Removed¶
Constructors: Removed constructors with
isKeepAlive
and/ordisableCache
parameters and kept those that set only either of uri/method/callback or all of them. The prefered way to set these properties are through their respective properties!Various ways to upload content:
RawData
, forms (exposed throughAddField
/AddBinaryData
andFormUsage
) are removed and merged into oneUploadStream
. Forms now can be uploaded through concrete, ready to use implementations:UrlEncodedStream
andMultipartFormDataStream
. To access more advanced scenarios an abstract class,UploadStreamBase
is also available for custom implementations, like the plugin's ownJSonDataStream
orDynamicUploadStream
. For examples about how to use them, please refer the plugin's samples.
Send a form multipart/form-data
encoded
UseUploadStreamLength:
UploadStreamBase
and its implementors must handle length calculations and what to return for unknown lengths.OnStreamingData, StreamFragmentSize, StreamChunksImmediately, ReadBufferSizeOverride, MaxFragmentQueueLength: These were hard to use properly, and now there's a new
DownloadContentStream
implementation to make download streaming easier.
Using DownloadContentStream
Relevant parts from the example that comes with the package:
Changed/Moved¶
- Moved properties under settings classes: Over the years as the HTTPRequest got more and more features, new properties and callbacks popped up one by one making it cluttered, unorganized. In this version, most of the properties and callbacks are still there with the same behavior, but located under setting classes.
Example with UploadStream
So, for example the above mentioned UploadStream moved into the UploadSettings class and can be accessed through a field with the same name in HTTPRequest:
Other upload related fields are relocated too, like OnUploadProgress
.
Here you can find a non-exhaustive list of these changes:
Member | Moved under | Accessible as |
---|---|---|
UploadStream | UploadSettings | request.UploadStettings.UploadStream = ...; |
OnUploadProgress | UploadSettings | request.UploadSettings.OnUploadProgress += ...; |
OnHeadersReceived | DownloadSettings | request.DownloadSettings.OnHeadersReceived += ...; |
OnDownloadStarted | DownloadSettings | request.DownloadSettings.OnDownloadStarted += ...; |
Timeout | TimeoutSettings | request.TimeoutSettings.Timeout = TimeSpan.FromSeconds(xy); |
ConnectTimeout | TimeoutSettings | request.TimeoutSettings.ConnectTimeout = TimeSpan.FromSeconds(xy); |
Retries | RetrySettings | request.RetrySettings.Retries = xy; |
MaxRetries | RetrySettings | request.RetrySettings.MaxRetries = xy; |
MaxRedirects | RedirectSettings | request.RedirectSettings.MaxRedirects = xy; |
Proxy | ProxySettings | request.ProxySettings.Proxy = new HTTPProxy(...); |
- Authententication: Instead of a single Credentials property, starting with this version authentication is implemented with the help of the IAuthenticator interface. The plugin ships with the CredentialAuthenticator and BearerTokenAuthenticator implementations. More details can be found in the Getting started/Authentication topic!
New¶
- Static functions for HTTPRequest creation : With the new static functions you can express more explicitly what type of request is created with less typeing.
- Instead of
new HTTPRequest("https://", HTTPMethods.Post, callback);
now it can be justHTTPRequest.CreatePOST("https://...", callback);
.
- Instead of
- New constructors: While I removed a few, I also added a few to support passing URLs as strings,
HTTPRequest
will convert them toSystem.Uri
instances. - Authenticator
3. HTTPResponse changes¶
Removed¶
- Cookies: Cookies aren't stored for each response, instead
CookieJar.Get(Uri uri)
can be used to get them on demain. - VersionMajor/VersionMinor: Merged them into one
public Version HTTPVersion { get; protected set; }
property. - IsStreamed: Removed, every response is streamed into the
HTTPResponse
'sDownStream
! - IsCacheOnly: The same information can acquired through the parent
HTTPRequest
. - CacheFileInfo: The same functionality should be possible with the new
HTTPCache
class, available asHTTPManager.LocalCache
. Let me know if you relied on it but can't find matching functionality. - IsProxyResponse: Removed without further explanation. Let me know if you relied on it but can't find matching functionality.
- IsClosedManually: Used by other protocols (Websocket, EventSource), now they are dealing with the connection differently.
Changed/Moved¶
Downloaded data handling (DownloadContentStream DownStream): As already mentioned, all downloads are streamed downloads downloading into a
DownloadContentStream
instance and its reference is stored intHTTPResponse
'sDownStream
. Buffering, thread synchronization and memory management is all done by theDownloadContentStream
. For smaller downloads, theHTTPResponse
still maintains its shortcuts:DataAsText
,DataAsTexture2D
and theData
property became a shortcut too:Example
- Allocate a large enough buffer
- Read all data to the buffer from the content stream
- Dispose the content stream
- Return with the buffer
New¶
- DownStream: Discussed above.
4. HTTPManager changes¶
Removed¶
- MaxPathLength: Removed without further explanation.
- IsCookiesEnabled: Removed without further explanation. If there will be any need to come back, it might be a new per-host setting somewhere.
- SendRequest(...): Removed without further explanation.
- SendBufferSize: Not a direct replacement, but plugin buffer sizes can be controlled through
Best.HTTP.Shared.HTTPManager.PerHostSettings.Get("*").LowLevelConnectionSettings.TCPWriteBufferSize
- ReceiveBufferSize: Not a direct replacement, but plugin buffer sizes can be controlled through
Best.HTTP.Shared.HTTPManager.PerHostSettings.Get("*").LowLevelConnectionSettings.ReadBufferSize
Changed/Moved¶
- MaxConnectionPerServer: Became a per-host setting, it can be changed for an arbitrary host or globally.
Example
- KeepAliveDefaultValue: Became a per-host setting, it can be changed for an arbitrary host or globally:
Example
- MaxConnectionIdleTime: Became a per-host setting, it can be changed for an arbitrary host or globally:
Example
- HTTP2Settings: Became a per-host setting, it can be changed for an arbitrary host or globally:
Example
- ConnectTimeout: Became a per-host setting, it can be changed for an arbitrary host or globally:
Example
- RequestTimeout: Became a per-host setting, it can be changed for an arbitrary host or globally:
Example
Warning
Its default value changed to never time out.
- IsCachingDisabled: Removed without further explanation, caching can be disabled per-request by setting the request's
DownloadSettings.DisableCache
to true. - CookieJarSize: =>
CookieJar.MaximumSize
- EnablePrivateBrowsing: =>
CookieJar.IsSessionOverride
- RootCacheFolderProvider: =>
RootSaveFolderProvider
- UserAgent: Changed its default value to include the package version set through AssemblyVersion.cs and the Unity runtime version:
Example
- TlsClientFactory: Became a per-host setting, it can be changed for an arbitrary host or globally:
Example
- DefaultTlsClientFactory: Moved under
Best.HTTP.Hosts.Settings.BouncyCastleSettings
- UseAlternateSSLDefaultValue: Became a per-host setting, it can be changed for an arbitrary host or globally:
Example
- DefaultCertificationValidator: Became a per-host setting, it can be changed for an arbitrary host or globally:
Example
- ClientCertificationProvider: Became a per-host setting, it can be changed for an arbitrary host or globally:
Example
New¶
- LocalCache: Instead of a static class, caching now can be accessed through
Best.HTTP.HTTPManager.LocalCache
, aHTTPCache
instance. - PerHostSettings: Most of the entries in the Changed/Moved section can be changed on a per-host basis through this field.
5. Caching changes¶
HTTP content caching is got completely reimplemented in the HTTPCache class. Demoted from a static class, its properties and functions can be accessed through Best.HTTP.HTTPManager.LocalCache
.
Most notable changes/features are:
- Maintenance is executed on every startup or when a new entry would increase the overall size over the limit.
- The maximum size of the cache is enforced during caching. In previous versions entries only evicted during maintanance.
- Headers and content now stored separately in different files. A file stream can be easily acquired by calling two functions.
6. Cookie changes¶
- Cookies can't be set directly for a
HTTPRequest
, but usingCookieJar.Set(Uri uri, Cookie cookie)
orCookieJar.Set(Cookie cookie)
. - Received cookies aren't stored for each
HTTPResponse
but they can be acquired with theCookieJar.Get(Uri uri)
function.
7. Authentication changes¶
Previous versions supported only HTTP authentication (Basic and Digest) through the Credentials property that allowed only to set a username-password pair. Starting with this version, authentication can be done by using an authenticator implementing the IAuthenticator
interface opening a wide range of possibilities.
The plugin ships with two IAuthenticator implementations, located in the Best.HTTP.Request.Authenticators
namespace:
CrendetialAuthenticator
to support the old behavior for Basic and Digest HTTP authentications.BearerTokenAuthenticator
to sendAuthorization
headers with a Bearer token.
General Tips¶
- Stay Updated on Documentation: Keep an eye on the official documentation for the Best HTTP package. It's regularly updated with new information, tutorials, and solutions to common problems.
- Engage with the Community: Join discussions on our Community and Support page to share your experiences, ask questions, and get advice on the upgrade process.
- Check for Updates Regularly: Ensure you always have the latest features, improvements, and bug fixes by regularly checking for updates.