Skip to content

Conversation

vaspadi
Copy link

@vaspadi vaspadi commented Aug 5, 2025

I’m using LongPollingTransport and needed to add a User-Agent header to the request. However, setHeaderValue had no effect in this case.

I came across PR #114 (Thanks to the author for the idea and initial implementation), which fixed a similar issue for WebSocketTransport. I used that PR as a foundation — I copied the relevant parts and adapted them to work with LongPollingTransport, adding my own changes where necessary.

Here’s how I configure the connection:

final serverUrl =
    '${hostUrl}signalr/hubs/AccountEventsHub?clientID=$clientID';
final headers = MessageHeaders();
headers.setHeaderValue(
  'User-Agent',
  httpClient.config.headers?['User-Agent'],
);

final httpOptions = HttpConnectionOptions(
  transport: HttpTransportType.LongPolling,
  headers: headers,
);

final hubConnection = HubConnectionBuilder()
    .withUrl(serverUrl, options: httpOptions)
    .withAutomaticReconnect()
    .build();
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants