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

Added CustomHeaders to WebSocketClient #22

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion websocket-sharp/Server/WebSocketServiceHostManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ public Dictionary<string, Dictionary<string, bool>> Broadping (string message)
if (message == null || message.Length == 0)
return Broadping ();

byte [] data;
byte [] data = null;
var msg = _state.CheckIfStarted () ??
(data = Encoding.UTF8.GetBytes (message)).CheckIfValidPingData ();

Expand Down
2 changes: 1 addition & 1 deletion websocket-sharp/Server/WebSocketSessionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ public Dictionary<string, bool> Broadping (string message)
if (message == null || message.Length == 0)
return Broadping ();

byte [] data;
byte [] data = null;
var msg = _state.CheckIfStarted () ??
(data = Encoding.UTF8.GetBytes (message)).CheckIfValidPingData ();

Expand Down
10 changes: 10 additions & 0 deletions websocket-sharp/WebSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ internal bool IsOpened {

#region Public Properties

public IEnumerable<KeyValuePair<string,string>> CustomHeaders { get; set; }

/// <summary>
/// Gets or sets the compression method used to compress the payload data of the WebSocket Data frame.
/// </summary>
Expand Down Expand Up @@ -714,6 +716,14 @@ private HandshakeRequest createHandshakeRequest ()

req.AddHeader ("Sec-WebSocket-Version", _version);

if (CustomHeaders != null)
{
foreach (var header in CustomHeaders)
{
req.AddHeader(header.Key, header.Value);
}
}

if (_preAuth && _credentials != null)
req.SetAuthorization (new AuthenticationResponse (_credentials));

Expand Down