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

Additional headers only sent on first request with negotiate, but not sending with message #102

Open
MohammadElKhatib opened this issue Dec 15, 2024 · 0 comments

Comments

@MohammadElKhatib
Copy link

I am using signalr_netcore: ^1.4.0 and flutter version 3.27.0 but as you can see i am still facing issue with the headers where i send an api key that is been sent during negotiate but not sent after that, below code and log

`
Future connectToHub() async {
Logger.root.level = Level.ALL;
_logMessagesSub = Logger.root.onRecord.listen(_handleLogMessage);
_logger = Logger("ChatPageViewModel");

final defaultHeaders = MessageHeaders();
defaultHeaders.setHeaderValue("X-Api-Key", apiKey);

var httpConnectionOptions = HttpConnectionOptions(
    accessTokenFactory: () => Future.value(getToken()),
    headers: defaultHeaders,
    logger: _logger,
    logMessageContent: true);

hubConnection = HubConnectionBuilder()
    .withUrl(chatHubUrl, options: httpConnectionOptions)
    .withAutomaticReconnect(retryDelays: [2000, 5000, 10000])
    .build();

hubConnection.onclose(({Exception? error}) {
  connectionIsOpen = false;
});

hubConnection.onreconnecting(({error}) {
  CustomLogger.devLog("onreconnecting called");
  connectionIsOpen = false;
});

hubConnection.onreconnected(({connectionId}) {
  CustomLogger.devLog("onreconnected called");
  connectionIsOpen = true;
});

hubConnection.on("ReceiveMessage", _handleIncomingChatMessage);
hubConnection.on("UserIsTyping", _handleUserIsTyping);
hubConnection.on("UserStatusUpdated", _handleUsersStatusUpdated);
await startConnection();

}
`

LOG:

[GETX] GOING TO ROUTE /chat
flutter: [2024-12-15 18:14:30.486698] [DEBUG]
flutter: Starting connection with transfer format 'TransferFormat.Text'.
[GETX] Instance "MessageController" has been created
[GETX] Instance "MessageController" has been initialized
flutter: [2024-12-15 18:14:30.496295] [DEBUG]
flutter: Sending negotiation request: https://localhost:7199/hub/chat/negotiate?negotiateVersion=1
flutter: [2024-12-15 18:14:30.496663] [DEBUG]
flutter: HTTP send: url 'https://localhost:7199/hub/chat/negotiate?negotiateVersion=1', method: 'POST' content: '' content length = '0' headers: '{ content-type: text/plain;charset=UTF-8 }, { X-Api-Key: ##### }, { X-Requested-With: FlutterHttpClient }, { Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWVfbmFtZSI6IjhlMWMwYjcxLTlkNWQtNGI0MS05NTUzLWYyNDA0ZmZkNDI1OCIsIm5hbWVpZCI6IjhlMWMwYjcxLTlkNWQtNGI0MS05NTUzLWYyNDA0ZmZkNDI1OCIsImVtYWlsIjoibW9oYW1tYWRhbGtoYXRpYkBvdXRsb29rLmNvbSIsImdpdmVuX25hbWUiOiJNTyBLSCIsIm5iZiI6MTczNDI3MjA0MiwiZXhwIjoxNzM0MjcyMTAyLCJpYXQiOjE3MzQyNzIwNDIsImlzcyI6ImxlYmFuZXNlc29vcS5jb20iLCJhdWQiOiJhcGkubGViYW5lc2Vzb29xLmNvbSJ9.PYY7B3NbEaaAhyYob4lpgKkx-gfOEjT-k4gbX40Ntvg }'
flutter: [2024-12-15 18:14:30.530043] [DEBUG]
flutter: Selecting transport 'HttpTransportType.WebSockets'.
flutter: [2024-12-15 18:14:30.530299] [DEBUG]
flutter: (WebSockets transport) Connecting
flutter: [2024-12-15 18:14:30.530563] [DEBUG]
flutter: WebSocket try connecting to 'wss://localhost:7199/hub/chat?id=gdzSwVPiNRd6EfeicZxP8w'.
flutter: [2024-12-15 18:14:30.559804] [DEBUG]
flutter: WebSocket connection to 'wss://localhost:7199/hub/chat?id=gdzSwVPiNRd6EfeicZxP8w' failed: WebSocketException: Connection to 'https://localhost:7199/hub/chat?id=gdzSwVPiNRd6EfeicZxP8w#' was not upgraded to websocket, HTTP status code: 403
flutter: [2024-12-15 18:14:30.560188] [DEBUG]
flutter: Failed to start the transport 'HttpTransportType.WebSockets': WebSocketException: Connection to 'https://localhost:7199/hub/chat?id=gdzSwVPiNRd6EfeicZxP8w#' was not upgraded to websocket, HTTP status code: 403
flutter: [2024-12-15 18:14:30.560358] [DEBUG]
flutter: Selecting transport 'HttpTransportType.ServerSentEvents'.
flutter: [2024-12-15 18:14:30.560603] [DEBUG]
flutter: Sending negotiation request: https://localhost:7199/hub/chat/negotiate?negotiateVersion=1
flutter: [2024-12-15 18:14:30.560989] [DEBUG]
flutter: HTTP send: url 'https://localhost:7199/hub/chat/negotiate?negotiateVersion=1', method: 'POST' content: '' content length = '0' headers: '{ content-type: text/plain;charset=UTF-8 }, { X-Api-Key: ##### }, { X-Requested-With: FlutterHttpClient }, { Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWVfbmFtZSI6IjhlMWMwYjcxLTlkNWQtNGI0MS05NTUzLWYyNDA0ZmZkNDI1OCIsIm5hbWVpZCI6IjhlMWMwYjcxLTlkNWQtNGI0MS05NTUzLWYyNDA0ZmZkNDI1OCIsImVtYWlsIjoibW9oYW1tYWRhbGtoYXRpYkBvdXRsb29rLmNvbSIsImdpdmVuX25hbWUiOiJNTyBLSCIsIm5iZiI6MTczNDI3MjA0MiwiZXhwIjoxNzM0MjcyMTAyLCJpYXQiOjE3MzQyNzIwNDIsImlzcyI6ImxlYmFuZXNlc29vcS5jb20iLCJhdWQiOiJhcGkubGViYW5lc2Vzb29xLmNvbSJ9.PYY7B3NbEaaAhyYob4lpgKkx-gfOEjT-k4gbX40Ntvg }'
flutter: [2024-12-15 18:14:30.586796] [DEBUG]
flutter: (SSE transport) Connecting
flutter: [2024-12-15 18:14:30.587551] [DEBUG]
flutter: (SSE transport) connected to https://localhost:7199/hub/chat?id=CukKT_HCHZzceDGqO_kdJQ&access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWVfbmFtZSI6IjhlMWMwYjcxLTlkNWQtNGI0MS05NTUzLWYyNDA0ZmZkNDI1OCIsIm5hbWVpZCI6IjhlMWMwYjcxLTlkNWQtNGI0MS05NTUzLWYyNDA0ZmZkNDI1OCIsImVtYWlsIjoibW9oYW1tYWRhbGtoYXRpYkBvdXRsb29rLmNvbSIsImdpdmVuX25hbWUiOiJNTyBLSCIsIm5iZiI6MTczNDI3MjA0MiwiZXhwIjoxNzM0MjcyMTAyLCJpYXQiOjE3MzQyNzIwNDIsImlzcyI6ImxlYmFuZXNlc29vcS5jb20iLCJhdWQiOiJhcGkubGViYW5lc2Vzb29xLmNvbSJ9.PYY7B3NbEaaAhyYob4lpgKkx-gfOEjT-k4gbX40Ntvg
flutter: [2024-12-15 18:14:30.587943] [DEBUG]
flutter: The HttpConnection connected successfully.
flutter: [2024-12-15 18:14:30.588228] [DEBUG]
flutter: (SSE transport) sending data.
flutter: [2024-12-15 18:14:30.588655] [DEBUG]
flutter: HTTP send: url 'https://localhost:7199/hub/chat?id=CukKT_HCHZzceDGqO_kdJQ', method: 'POST' content: '{"protocol":"json","version":1}^^' content length = '32' headers: '{ content-type: application/json;charset=UTF-8 }, { X-Requested-With: FlutterHttpClient }, { Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWVfbmFtZSI6IjhlMWMwYjcxLTlkNWQtNGI0MS05NTUzLWYyNDA0ZmZkNDI1OCIsIm5hbWVpZCI6IjhlMWMwYjcxLTlkNWQtNGI0MS05NTUzLWYyNDA0ZmZkNDI1OCIsImVtYWlsIjoibW9oYW1tYWRhbGtoYXRpYkBvdXRsb29rLmNvbSIsImdpdmVuX25hbWUiOiJNTyBLSCIsIm5iZiI6MTczNDI3MjA0MiwiZXhwIjoxNzM0MjcyMTAyLCJpYXQiOjE3MzQyNzIwNDIsImlzcyI6ImxlYmFuZXNlc29vcS5jb20iLCJhdWQiOiJhcGkubGViYW5lc2Vzb29xLmNvbSJ9.PYY7B3NbEaaAhyYob4lpgKkx-gfOEjT-k4gbX40Ntvg <…>
flutter: [2024-12-15 18:14:30.625311] [DEBUG]
flutter: HttpConnection.stopConnection(Unknown) called while in state ConnectionState.Disconnecting.
flutter: [2024-12-15 18:14:30.625563] [DEBUG]
flutter: Connection disconnected with error 'Exception: 403: Forbidden'.
[ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: 403: Forbidden

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

No branches or pull requests

1 participant