Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Timeout option for requests to resolve unexpected Timeout Exceptions #20

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions lib/http_connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ class TransportSendQueue {
class HttpConnection implements IConnection {
// Properties
static final maxRedirects = 100;
static final maxRequestTimeoutMilliseconds = 2000;

ConnectionState? _connectionState;
// connectionStarted is tracked independently from connectionState, so we can check if the
Expand Down Expand Up @@ -450,9 +449,7 @@ class HttpConnection implements IConnection {
_logger?.finer("Sending negotiation request: $negotiateUrl");
try {
final SignalRHttpRequest options = SignalRHttpRequest(
content: "",
headers: headers,
timeout: maxRequestTimeoutMilliseconds);
content: "", headers: headers, timeout: _options.requestTimeout);
final response = await _httpClient.post(negotiateUrl, options: options);

if (response.statusCode != 200) {
Expand Down
9 changes: 7 additions & 2 deletions lib/http_connection_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class HttpConnectionOptions {
///
bool skipNegotiation;

/// An int that reflects the time to wait for a request to complete before throwing a TimeoutError. Measured in milliseconds.
int requestTimeout;

// Methods
HttpConnectionOptions(
{SignalRHttpClient? httpClient,
Expand All @@ -47,12 +50,14 @@ class HttpConnectionOptions {
AccessTokenFactory? accessTokenFactory,
MessageHeaders? headers,
bool logMessageContent = false,
bool skipNegotiation = false})
bool skipNegotiation = false,
int requestTimeout = 2000})
: this.httpClient = httpClient,
this.transport = transport,
this.logger = logger,
this.accessTokenFactory = accessTokenFactory,
this.headers = headers,
this.logMessageContent = logMessageContent,
this.skipNegotiation = skipNegotiation;
this.skipNegotiation = skipNegotiation,
this.requestTimeout = requestTimeout;
}