Advanced Request Parameters¶
HTTPRequest keeps redirection, timeout, and proxy behavior on dedicated settings objects. Per-request values override the matching per-host settings.
Redirection¶
Redirection is enabled by default. RedirectSettings.MaxRedirects starts at 10. Set it to 0 or a negative value to refuse redirections for that request:
The plugin follows a Location header for these status codes:
301 Moved Permanently302 Found303 See Other307 Temporary Redirect308 Permanent Redirect
A redirect without a Location header finishes as an error. A Location that points at the request's current URI is not followed. While the request is redirected, HTTPRequest.CurrentUri returns the latest target and HTTPRequest.Uri stays the URI the request was created with.
The HTTP method is kept for every followed redirect, including 301, 302, and 303.
The plugin sets Referer to the URI it just left. When the new host differs from the current one, it also removes headers that must not be sent to another origin: Authorization, Cookie, Origin, Host, Proxy-Authorization, cache validators (If-None-Match, If-Modified-Since), and Content-Length.
OnBeforeRedirection runs before that new request is sent, on a thread other than Unity's main thread. Return false to stop following the redirect and surface the redirect response instead:
IsRedirected can be true while RedirectCount is still 0. That happens when the local cache serves the response, which is also modeled as a redirection.
Timeouts¶
Each request has a TimeoutSettings instance. Values left unset fall back to the host's HTTRequestSettings:
| Setting | What it limits | Default |
|---|---|---|
ConnectTimeout | Time spent waiting for a connection after the request is queued | 20 seconds |
Timeout | Time spent processing the request after a connection starts working on it | TimeSpan.MaxValue |
TimeSpan.Zero or a negative ConnectTimeout disables the connect timeout. The request timeout is effectively disabled until a shorter value is assigned, because the default is TimeSpan.MaxValue.
Set them for one request:
Or for every host:
A connect timeout finishes the request in HTTPRequestStates.ConnectionTimedOut. A processing timeout finishes it in HTTPRequestStates.TimedOut. Once processing has started, only the request timeout applies.
Custom Proxy¶
HTTPManager.Proxy is copied onto each new request. Assign request.ProxySettings.Proxy to use a different proxy, or set it to null to bypass the global proxy for that call:
How to configure HTTP and SOCKS proxies is covered in HTTP Proxies and SOCKSv5 Proxies. Automatic detection is covered in Proxy Autodetect.