fix: custom headers with sockets
This commit is contained in:
@@ -52,10 +52,41 @@ class SocketService {
|
|||||||
.setTimeout(20000)
|
.setTimeout(20000)
|
||||||
.setPath(path);
|
.setPath(path);
|
||||||
|
|
||||||
|
// Merge Authorization (if any) with user-defined custom headers for the
|
||||||
|
// Socket.IO handshake. Avoid overriding reserved headers.
|
||||||
|
final Map<String, String> extraHeaders = {};
|
||||||
if (authToken != null && authToken!.isNotEmpty) {
|
if (authToken != null && authToken!.isNotEmpty) {
|
||||||
builder
|
extraHeaders['Authorization'] = 'Bearer $authToken';
|
||||||
.setAuth({'token': authToken})
|
builder.setAuth({'token': authToken});
|
||||||
.setExtraHeaders({'Authorization': 'Bearer $authToken'});
|
}
|
||||||
|
if (serverConfig.customHeaders.isNotEmpty) {
|
||||||
|
final reserved = {
|
||||||
|
'authorization',
|
||||||
|
'content-type',
|
||||||
|
'accept',
|
||||||
|
// Socket/WebSocket reserved or managed by client/runtime
|
||||||
|
'host',
|
||||||
|
'origin',
|
||||||
|
'connection',
|
||||||
|
'upgrade',
|
||||||
|
'sec-websocket-key',
|
||||||
|
'sec-websocket-version',
|
||||||
|
'sec-websocket-extensions',
|
||||||
|
'sec-websocket-protocol',
|
||||||
|
};
|
||||||
|
serverConfig.customHeaders.forEach((key, value) {
|
||||||
|
final lower = key.toLowerCase();
|
||||||
|
if (!reserved.contains(lower) && value.isNotEmpty) {
|
||||||
|
// Do not overwrite Authorization we already set from authToken
|
||||||
|
if (lower == 'authorization' && extraHeaders.containsKey('Authorization')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
extraHeaders[key] = value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (extraHeaders.isNotEmpty) {
|
||||||
|
builder.setExtraHeaders(extraHeaders);
|
||||||
}
|
}
|
||||||
|
|
||||||
_socket = io.io(base, builder.build());
|
_socket = io.io(base, builder.build());
|
||||||
|
|||||||
@@ -674,11 +674,19 @@ class _ServerConnectionPageState extends ConsumerState<ServerConnectionPage> {
|
|||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
ConduitBadge(
|
// Make the header badge flexible and truncate long text
|
||||||
text: entry.key,
|
Flexible(
|
||||||
backgroundColor: context.conduitTheme.buttonPrimary.withValues(alpha: 0.1),
|
fit: FlexFit.loose,
|
||||||
textColor: context.conduitTheme.buttonPrimary,
|
child: ConduitBadge(
|
||||||
isCompact: true,
|
text: entry.key,
|
||||||
|
backgroundColor:
|
||||||
|
context.conduitTheme.buttonPrimary.withValues(alpha: 0.1),
|
||||||
|
textColor: context.conduitTheme.buttonPrimary,
|
||||||
|
isCompact: true,
|
||||||
|
maxLines: 1,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
softWrap: false,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: Spacing.md),
|
const SizedBox(width: Spacing.md),
|
||||||
Expanded(
|
Expanded(
|
||||||
|
|||||||
@@ -562,6 +562,10 @@ class ConduitBadge extends StatelessWidget {
|
|||||||
final Color? backgroundColor;
|
final Color? backgroundColor;
|
||||||
final Color? textColor;
|
final Color? textColor;
|
||||||
final bool isCompact;
|
final bool isCompact;
|
||||||
|
// Optional text behavior controls for truncation/wrapping
|
||||||
|
final int? maxLines;
|
||||||
|
final TextOverflow? overflow;
|
||||||
|
final bool? softWrap;
|
||||||
|
|
||||||
const ConduitBadge({
|
const ConduitBadge({
|
||||||
super.key,
|
super.key,
|
||||||
@@ -569,6 +573,9 @@ class ConduitBadge extends StatelessWidget {
|
|||||||
this.backgroundColor,
|
this.backgroundColor,
|
||||||
this.textColor,
|
this.textColor,
|
||||||
this.isCompact = false,
|
this.isCompact = false,
|
||||||
|
this.maxLines,
|
||||||
|
this.overflow,
|
||||||
|
this.softWrap,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -592,6 +599,9 @@ class ConduitBadge extends StatelessWidget {
|
|||||||
color: textColor ?? context.conduitTheme.buttonPrimary,
|
color: textColor ?? context.conduitTheme.buttonPrimary,
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
),
|
),
|
||||||
|
maxLines: maxLines,
|
||||||
|
overflow: overflow,
|
||||||
|
softWrap: softWrap,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user