bool CookieValidator(CookieCollection req, CookieCollection res) { string InternalRunningSessionID = req["Agent-SessionID"].Value; if (string.IsNullOrWhiteSpace(InternalRunningSessionID) == true) { return(false); } NetworkConnectionInfo ni = NetworkConnection.GetSession(InternalRunningSessionID); if (ni == null) { return(false); } if (ni.ComputerLoggedIn == false) { return(false); } lock (RemoteNetworkConnectionWSCrosser.DictLock) { if (RemoteNetworkConnectionWSCrosser.Sessions.ContainsKey(SessionID) == false) { return(false); } if (RemoteNetworkConnectionWSCrosser.Sessions[SessionID].MachineID != ni.Username) { return(false); } } Debug.WriteLine("Cookie (AG-SPM) validated"); return(true); }
/// <summary> /// Gets the collection of the HTTP cookies from the specified HTTP <paramref name="headers" />. /// </summary> /// <returns> /// A <see cref="Net.CookieCollection" /> that receives a collection of the HTTP cookies. /// </returns> /// <param name="headers"> /// A <see cref="NameValueCollection" /> that contains a collection of the HTTP headers. /// </param> /// <param name="response"> /// <c>true</c> if <paramref name="headers" /> is a collection of the response headers; /// otherwise, <c>false</c>. /// </param> public static CookieCollection GetCookies(this NameValueCollection headers, bool response) { var name = response ? "Set-Cookie" : "Cookie"; return(headers != null && headers.Contains(name) ? CookieCollection.Parse(headers[name], response) : new CookieCollection()); }
protected override bool ValidateCookies(CookieCollection request, CookieCollection response) { foreach (Cookie cookie in request) { cookie.Expired = true; response.Add (cookie); } return true; }
// As server private bool validateCookies(CookieCollection request, CookieCollection response) { return _cookiesValidation != null ? _cookiesValidation (request, response) : true; }
/// <summary> /// Validates the cookies used in the WebSocket connection request. /// </summary> /// <remarks> /// This method is called when the inner <see cref="WebSocket"/> validates /// the WebSocket connection request. /// </remarks> /// <returns> /// <c>true</c> if the cookies is valid; otherwise, <c>false</c>. /// The default returns <c>true</c>. /// </returns> /// <param name="request"> /// A <see cref="CookieCollection"/> that contains a collection of the HTTP Cookies /// to validate. /// </param> /// <param name="response"> /// A <see cref="CookieCollection"/> that receives the HTTP Cookies to send to the client. /// </param> protected virtual bool ValidateCookies(CookieCollection request, CookieCollection response) { return true; }
/// <summary> /// Adds the specified <paramref name="cookies"/> to the collection. /// </summary> /// <param name="cookies"> /// A <see cref="CookieCollection"/> that contains the cookies to add. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="cookies"/> is <see langword="null"/>. /// </exception> public void Add (CookieCollection cookies) { if (cookies == null) throw new ArgumentNullException ("cookies"); foreach (Cookie cookie in cookies) Add (cookie); }
private static CookieCollection parseResponse (string value) { var cookies = new CookieCollection (); Cookie cookie = null; var pairs = splitCookieHeaderValue (value); for (var i = 0; i < pairs.Length; i++) { var pair = pairs[i].Trim (); if (pair.Length == 0) continue; if (pair.StartsWith ("version", StringComparison.InvariantCultureIgnoreCase)) { if (cookie != null) cookie.Version = Int32.Parse (pair.GetValue ('=', true)); } else if (pair.StartsWith ("expires", StringComparison.InvariantCultureIgnoreCase)) { var buff = new StringBuilder (pair.GetValue ('='), 32); if (i < pairs.Length - 1) buff.AppendFormat (", {0}", pairs[++i].Trim ()); DateTime expires; if (!DateTime.TryParseExact ( buff.ToString (), new[] { "ddd, dd'-'MMM'-'yyyy HH':'mm':'ss 'GMT'", "r" }, CultureInfo.CreateSpecificCulture ("en-US"), DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal, out expires)) expires = DateTime.Now; if (cookie != null && cookie.Expires == DateTime.MinValue) cookie.Expires = expires.ToLocalTime (); } else if (pair.StartsWith ("max-age", StringComparison.InvariantCultureIgnoreCase)) { var max = Int32.Parse (pair.GetValue ('=', true)); var expires = DateTime.Now.AddSeconds ((double) max); if (cookie != null) cookie.Expires = expires; } else if (pair.StartsWith ("path", StringComparison.InvariantCultureIgnoreCase)) { if (cookie != null) cookie.Path = pair.GetValue ('='); } else if (pair.StartsWith ("domain", StringComparison.InvariantCultureIgnoreCase)) { if (cookie != null) cookie.Domain = pair.GetValue ('='); } else if (pair.StartsWith ("port", StringComparison.InvariantCultureIgnoreCase)) { var port = pair.Equals ("port", StringComparison.InvariantCultureIgnoreCase) ? "\"\"" : pair.GetValue ('='); if (cookie != null) cookie.Port = port; } else if (pair.StartsWith ("comment", StringComparison.InvariantCultureIgnoreCase)) { if (cookie != null) cookie.Comment = pair.GetValue ('=').UrlDecode (); } else if (pair.StartsWith ("commenturl", StringComparison.InvariantCultureIgnoreCase)) { if (cookie != null) cookie.CommentUri = pair.GetValue ('=', true).ToUri (); } else if (pair.StartsWith ("discard", StringComparison.InvariantCultureIgnoreCase)) { if (cookie != null) cookie.Discard = true; } else if (pair.StartsWith ("secure", StringComparison.InvariantCultureIgnoreCase)) { if (cookie != null) cookie.Secure = true; } else if (pair.StartsWith ("httponly", StringComparison.InvariantCultureIgnoreCase)) { if (cookie != null) cookie.HttpOnly = true; } else { if (cookie != null) cookies.Add (cookie); string name; string val = String.Empty; var pos = pair.IndexOf ('='); if (pos == -1) { name = pair; } else if (pos == pair.Length - 1) { name = pair.Substring (0, pos).TrimEnd (' '); } else { name = pair.Substring (0, pos).TrimEnd (' '); val = pair.Substring (pos + 1).TrimStart (' '); } cookie = new Cookie (name, val); } } if (cookie != null) cookies.Add (cookie); return cookies; }
// As client private void processCookies (CookieCollection cookies) { if (cookies.Count == 0) return; _cookies.SetOrRemove (cookies); }
internal void AddHeader(string header) { int colon = header.IndexOf(':'); if (colon == -1 || colon == 0) { context.ErrorMessage = "Bad Request"; context.ErrorStatus = 400; return; } string name = header.Substring(0, colon).Trim(); string val = header.Substring(colon + 1).Trim(); string lower = name.ToLower(CultureInfo.InvariantCulture); headers.SetInternal(name, val); switch (lower) { case "accept-language": user_languages = val.Split(','); // yes, only split with a ',' break; case "accept": accept_types = val.Split(','); // yes, only split with a ',' break; case "content-length": try { //TODO: max. content_length? content_length = Int64.Parse(val.Trim()); if (content_length < 0) { context.ErrorMessage = "Invalid Content-Length."; } cl_set = true; } catch { context.ErrorMessage = "Invalid Content-Length."; } break; case "referer": try { referrer = new Uri(val); } catch { referrer = new Uri("http://someone.is.screwing.with.the.headers.com/"); } break; case "cookie": if (cookies == null) { cookies = new CookieCollection(); } string[] cookieStrings = val.Split(new char[] { ',', ';' }); Cookie current = null; int version = 0; foreach (string cookieString in cookieStrings) { string str = cookieString.Trim(); if (str.Length == 0) { continue; } if (str.StartsWith("$Version")) { version = Int32.Parse(Unquote(str.Substring(str.IndexOf('=') + 1))); } else if (str.StartsWith("$Path")) { if (current != null) { current.Path = str.Substring(str.IndexOf('=') + 1).Trim(); } } else if (str.StartsWith("$Domain")) { if (current != null) { current.Domain = str.Substring(str.IndexOf('=') + 1).Trim(); } } else if (str.StartsWith("$Port")) { if (current != null) { current.Port = str.Substring(str.IndexOf('=') + 1).Trim(); } } else { if (current != null) { cookies.Add(current); } current = new Cookie(); int idx = str.IndexOf('='); if (idx > 0) { current.Name = str.Substring(0, idx).Trim(); current.Value = str.Substring(idx + 1).Trim(); } else { current.Name = str.Trim(); current.Value = String.Empty; } current.Version = version; } } if (current != null) { cookies.Add(current); } break; } }
private static CookieCollection parseResponse(string value) { DateTime now; string str; CookieCollection cookieCollections = new CookieCollection(); Cookie localTime = null; string[] strArrays = CookieCollection.splitCookieHeaderValue(value); for (int i = 0; i < (int)strArrays.Length; i++) { string str1 = strArrays[i].Trim(); if (str1.Length != 0) { if (str1.StartsWith("version", StringComparison.InvariantCultureIgnoreCase)) { if (localTime != null) { localTime.Version = int.Parse(str1.GetValue('=', true)); } } else if (str1.StartsWith("expires", StringComparison.InvariantCultureIgnoreCase)) { StringBuilder stringBuilder = new StringBuilder(str1.GetValue('='), 32); if (i < (int)strArrays.Length - 1) { int num = i + 1; i = num; stringBuilder.AppendFormat(", {0}", strArrays[num].Trim()); } if (!DateTime.TryParseExact(stringBuilder.ToString(), new string[] { "ddd, dd'-'MMM'-'yyyy HH':'mm':'ss 'GMT'", "r" }, CultureInfo.CreateSpecificCulture("en-US"), DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal, out now)) { now = DateTime.Now; } if ((localTime == null ? false : localTime.Expires == DateTime.MinValue)) { localTime.Expires = now.ToLocalTime(); } } else if (str1.StartsWith("max-age", StringComparison.InvariantCultureIgnoreCase)) { int num1 = int.Parse(str1.GetValue('=', true)); DateTime dateTime = DateTime.Now.AddSeconds((double)num1); if (localTime != null) { localTime.Expires = dateTime; } } else if (str1.StartsWith("path", StringComparison.InvariantCultureIgnoreCase)) { if (localTime != null) { localTime.Path = str1.GetValue('='); } } else if (str1.StartsWith("domain", StringComparison.InvariantCultureIgnoreCase)) { if (localTime != null) { localTime.Domain = str1.GetValue('='); } } else if (str1.StartsWith("port", StringComparison.InvariantCultureIgnoreCase)) { string str2 = (str1.Equals("port", StringComparison.InvariantCultureIgnoreCase) ? "\"\"" : str1.GetValue('=')); if (localTime != null) { localTime.Port = str2; } } else if (str1.StartsWith("comment", StringComparison.InvariantCultureIgnoreCase)) { if (localTime != null) { localTime.Comment = str1.GetValue('=').UrlDecode(); } } else if (str1.StartsWith("commenturl", StringComparison.InvariantCultureIgnoreCase)) { if (localTime != null) { localTime.CommentUri = str1.GetValue('=', true).ToUri(); } } else if (str1.StartsWith("discard", StringComparison.InvariantCultureIgnoreCase)) { if (localTime != null) { localTime.Discard = true; } } else if (str1.StartsWith("secure", StringComparison.InvariantCultureIgnoreCase)) { if (localTime != null) { localTime.Secure = true; } } else if (!str1.StartsWith("httponly", StringComparison.InvariantCultureIgnoreCase)) { if (localTime != null) { cookieCollections.Add(localTime); } string empty = string.Empty; int num2 = str1.IndexOf('='); if (num2 == -1) { str = str1; } else if (num2 != str1.Length - 1) { str = str1.Substring(0, num2).TrimEnd(new char[] { ' ' }); empty = str1.Substring(num2 + 1).TrimStart(new char[] { ' ' }); } else { str = str1.Substring(0, num2).TrimEnd(new char[] { ' ' }); } localTime = new Cookie(str, empty); } else if (localTime != null) { localTime.HttpOnly = true; } } } if (localTime != null) { cookieCollections.Add(localTime); } return(cookieCollections); }
private static CookieCollection parseRequest(string value) { string str; CookieCollection cookieCollections = new CookieCollection(); Cookie cookie = null; int num = 0; string[] strArrays = CookieCollection.splitCookieHeaderValue(value); for (int i = 0; i < (int)strArrays.Length; i++) { string str1 = strArrays[i].Trim(); if (str1.Length != 0) { if (str1.StartsWith("$version", StringComparison.InvariantCultureIgnoreCase)) { num = int.Parse(str1.GetValue('=', true)); } else if (str1.StartsWith("$path", StringComparison.InvariantCultureIgnoreCase)) { if (cookie != null) { cookie.Path = str1.GetValue('='); } } else if (str1.StartsWith("$domain", StringComparison.InvariantCultureIgnoreCase)) { if (cookie != null) { cookie.Domain = str1.GetValue('='); } } else if (!str1.StartsWith("$port", StringComparison.InvariantCultureIgnoreCase)) { if (cookie != null) { cookieCollections.Add(cookie); } string empty = string.Empty; int num1 = str1.IndexOf('='); if (num1 == -1) { str = str1; } else if (num1 != str1.Length - 1) { str = str1.Substring(0, num1).TrimEnd(new char[] { ' ' }); empty = str1.Substring(num1 + 1).TrimStart(new char[] { ' ' }); } else { str = str1.Substring(0, num1).TrimEnd(new char[] { ' ' }); } cookie = new Cookie(str, empty); if (num != 0) { cookie.Version = num; } } else { string str2 = (str1.Equals("$port", StringComparison.InvariantCultureIgnoreCase) ? "\"\"" : str1.GetValue('=')); if (cookie != null) { cookie.Port = str2; } } } } if (cookie != null) { cookieCollections.Add(cookie); } return(cookieCollections); }
internal static CookieCollection Parse(string value, bool response) { return(response ? CookieCollection.parseResponse(value) : CookieCollection.parseRequest(value)); }
private void init () { _compression = CompressionMethod.NONE; _cookies = new CookieCollection (); _extensions = String.Empty; _forClose = new object (); _forConnect = new object (); _forSend = new object (); _protocol = String.Empty; _readyState = WebSocketState.CONNECTING; }
public CookieCollection(string headers) { CookieCollection tmp = CookieCollection.parseRequest(headers); _list = new List <Cookie> (tmp._list); }
private static CookieCollection parseResponse(string value) { var ret = new CookieCollection(); Cookie cookie = null; var caseInsensitive = StringComparison.InvariantCultureIgnoreCase; var pairs = value.SplitHeaderValue(',', ';').ToList(); for (var i = 0; i < pairs.Count; i++) { var pair = pairs[i].Trim(); if (pair.Length == 0) { continue; } var idx = pair.IndexOf('='); if (idx == -1) { if (cookie == null) { continue; } if (pair.Equals("port", caseInsensitive)) { cookie.Port = "\"\""; continue; } if (pair.Equals("discard", caseInsensitive)) { cookie.Discard = true; continue; } if (pair.Equals("secure", caseInsensitive)) { cookie.Secure = true; continue; } if (pair.Equals("httponly", caseInsensitive)) { cookie.HttpOnly = true; continue; } continue; } if (idx == 0) { if (cookie != null) { ret.add(cookie); cookie = null; } continue; } var name = pair.Substring(0, idx).TrimEnd(' '); var val = idx < pair.Length - 1 ? pair.Substring(idx + 1).TrimStart(' ') : String.Empty; if (name.Equals("version", caseInsensitive)) { if (cookie == null) { continue; } if (val.Length == 0) { continue; } int num; if (!Int32.TryParse(val.Unquote(), out num)) { continue; } cookie.Version = num; continue; } if (name.Equals("expires", caseInsensitive)) { if (val.Length == 0) { continue; } if (i == pairs.Count - 1) { break; } i++; if (cookie == null) { continue; } if (cookie.Expires != DateTime.MinValue) { continue; } var buff = new StringBuilder(val, 32); buff.AppendFormat(", {0}", pairs[i].Trim()); DateTime expires; if ( !DateTime.TryParseExact( buff.ToString(), new[] { "ddd, dd'-'MMM'-'yyyy HH':'mm':'ss 'GMT'", "r" }, CultureInfo.CreateSpecificCulture("en-US"), DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal, out expires ) ) { continue; } cookie.Expires = expires.ToLocalTime(); continue; } if (name.Equals("max-age", caseInsensitive)) { if (cookie == null) { continue; } if (val.Length == 0) { continue; } int num; if (!Int32.TryParse(val.Unquote(), out num)) { continue; } cookie.MaxAge = num; continue; } if (name.Equals("path", caseInsensitive)) { if (cookie == null) { continue; } if (val.Length == 0) { continue; } cookie.Path = val; continue; } if (name.Equals("domain", caseInsensitive)) { if (cookie == null) { continue; } if (val.Length == 0) { continue; } cookie.Domain = val; continue; } if (name.Equals("port", caseInsensitive)) { if (cookie == null) { continue; } if (val.Length == 0) { continue; } cookie.Port = val; continue; } if (name.Equals("comment", caseInsensitive)) { if (cookie == null) { continue; } if (val.Length == 0) { continue; } cookie.Comment = urlDecode(val, Encoding.UTF8); continue; } if (name.Equals("commenturl", caseInsensitive)) { if (cookie == null) { continue; } if (val.Length == 0) { continue; } cookie.CommentUri = val.Unquote().ToUri(); continue; } if (name.Equals("samesite", caseInsensitive)) { if (cookie == null) { continue; } if (val.Length == 0) { continue; } cookie.SameSite = val.Unquote(); continue; } if (cookie != null) { ret.add(cookie); } Cookie.TryCreate(name, val, out cookie); } if (cookie != null) { ret.add(cookie); } return(ret); }
public void SetCookies(CookieCollection cookies) { if (cookies.IsNull() || cookies.Count == 0) return; var sorted = cookies.Sorted.ToArray(); var header = new StringBuilder(sorted[0].ToString()); for (int i = 1; i < sorted.Length; i++) if (!sorted[i].Expired) header.AppendFormat("; {0}", sorted[i].ToString()); AddHeader("Cookie", header.ToString()); }
private static CookieCollection parseRequest(string value) { var cookies = new CookieCollection(); Cookie cookie = null; var ver = 0; var pairs = splitCookieHeaderValue(value); for (var i = 0; i < pairs.Length; i++) { var pair = pairs[i].Trim(); if (pair.Length == 0) { continue; } if (pair.StartsWith("$version", StringComparison.InvariantCultureIgnoreCase)) { ver = Int32.Parse(pair.GetValue('=', true)); } else if (pair.StartsWith("$path", StringComparison.InvariantCultureIgnoreCase)) { if (cookie != null) { cookie.Path = pair.GetValue('='); } } else if (pair.StartsWith("$domain", StringComparison.InvariantCultureIgnoreCase)) { if (cookie != null) { cookie.Domain = pair.GetValue('='); } } else if (pair.StartsWith("$port", StringComparison.InvariantCultureIgnoreCase)) { var port = pair.Equals("$port", StringComparison.InvariantCultureIgnoreCase) ? "\"\"" : pair.GetValue('='); if (cookie != null) { cookie.Port = port; } } else { if (cookie != null) { cookies.Add(cookie); } string name; string val = String.Empty; var pos = pair.IndexOf('='); if (pos == -1) { name = pair; } else if (pos == pair.Length - 1) { name = pair.Substring(0, pos).TrimEnd(' '); } else { name = pair.Substring(0, pos).TrimEnd(' '); val = pair.Substring(pos + 1).TrimStart(' '); } cookie = new Cookie(name, val); if (ver != 0) { cookie.Version = ver; } } } if (cookie != null) { cookies.Add(cookie); } return(cookies); }
// As client private void processResponseCookies(CookieCollection cookies) { if (cookies.Count > 0) _cookies.SetOrRemove(cookies); }
private static CookieCollection parseResponse(string value) { var cookies = new CookieCollection(); Cookie cookie = null; var pairs = splitCookieHeaderValue(value); for (var i = 0; i < pairs.Length; i++) { var pair = pairs[i].Trim(); if (pair.Length == 0) { continue; } if (pair.StartsWith("version", StringComparison.InvariantCultureIgnoreCase)) { if (cookie != null) { cookie.Version = Int32.Parse(pair.GetValue('=', true)); } } else if (pair.StartsWith("expires", StringComparison.InvariantCultureIgnoreCase)) { var buff = new StringBuilder(pair.GetValue('='), 32); if (i < pairs.Length - 1) { buff.AppendFormat(", {0}", pairs[++i].Trim()); } DateTime expires; if (!DateTime.TryParseExact( buff.ToString(), new[] { "ddd, dd'-'MMM'-'yyyy HH':'mm':'ss 'GMT'", "r" }, CultureInfo.CreateSpecificCulture("en-US"), DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal, out expires)) { expires = DateTime.Now; } if (cookie != null && cookie.Expires == DateTime.MinValue) { cookie.Expires = expires.ToLocalTime(); } } else if (pair.StartsWith("max-age", StringComparison.InvariantCultureIgnoreCase)) { var max = Int32.Parse(pair.GetValue('=', true)); var expires = DateTime.Now.AddSeconds((double)max); if (cookie != null) { cookie.Expires = expires; } } else if (pair.StartsWith("path", StringComparison.InvariantCultureIgnoreCase)) { if (cookie != null) { cookie.Path = pair.GetValue('='); } } else if (pair.StartsWith("domain", StringComparison.InvariantCultureIgnoreCase)) { if (cookie != null) { cookie.Domain = pair.GetValue('='); } } else if (pair.StartsWith("port", StringComparison.InvariantCultureIgnoreCase)) { var port = pair.Equals("port", StringComparison.InvariantCultureIgnoreCase) ? "\"\"" : pair.GetValue('='); if (cookie != null) { cookie.Port = port; } } else if (pair.StartsWith("comment", StringComparison.InvariantCultureIgnoreCase)) { if (cookie != null) { cookie.Comment = urlDecode(pair.GetValue('='), Encoding.UTF8); } } else if (pair.StartsWith("commenturl", StringComparison.InvariantCultureIgnoreCase)) { if (cookie != null) { cookie.CommentUri = pair.GetValue('=', true).ToUri(); } } else if (pair.StartsWith("discard", StringComparison.InvariantCultureIgnoreCase)) { if (cookie != null) { cookie.Discard = true; } } else if (pair.StartsWith("secure", StringComparison.InvariantCultureIgnoreCase)) { if (cookie != null) { cookie.Secure = true; } } else if (pair.StartsWith("httponly", StringComparison.InvariantCultureIgnoreCase)) { if (cookie != null) { cookie.HttpOnly = true; } } else { if (cookie != null) { cookies.Add(cookie); } string name; string val = String.Empty; var pos = pair.IndexOf('='); if (pos == -1) { name = pair; } else if (pos == pair.Length - 1) { name = pair.Substring(0, pos).TrimEnd(' '); } else { name = pair.Substring(0, pos).TrimEnd(' '); val = pair.Substring(pos + 1).TrimStart(' '); } cookie = new Cookie(name, val); } } if (cookie != null) { cookies.Add(cookie); } return(cookies); }
private static CookieCollection parseRequest (string value) { var cookies = new CookieCollection (); Cookie cookie = null; var ver = 0; var pairs = splitCookieHeaderValue (value); for (var i = 0; i < pairs.Length; i++) { var pair = pairs[i].Trim (); if (pair.Length == 0) continue; if (pair.StartsWith ("$version", StringComparison.InvariantCultureIgnoreCase)) { ver = Int32.Parse (pair.GetValue ('=', true)); } else if (pair.StartsWith ("$path", StringComparison.InvariantCultureIgnoreCase)) { if (cookie != null) cookie.Path = pair.GetValue ('='); } else if (pair.StartsWith ("$domain", StringComparison.InvariantCultureIgnoreCase)) { if (cookie != null) cookie.Domain = pair.GetValue ('='); } else if (pair.StartsWith ("$port", StringComparison.InvariantCultureIgnoreCase)) { var port = pair.Equals ("$port", StringComparison.InvariantCultureIgnoreCase) ? "\"\"" : pair.GetValue ('='); if (cookie != null) cookie.Port = port; } else { if (cookie != null) cookies.Add (cookie); string name; string val = String.Empty; var pos = pair.IndexOf ('='); if (pos == -1) { name = pair; } else if (pos == pair.Length - 1) { name = pair.Substring (0, pos).TrimEnd (' '); } else { name = pair.Substring (0, pos).TrimEnd (' '); val = pair.Substring (pos + 1).TrimStart (' '); } cookie = new Cookie (name, val); if (ver != 0) cookie.Version = ver; } } if (cookie != null) cookies.Add (cookie); return cookies; }
/// <summary> /// Processes the cookies used in the WebSocket opening handshake. /// </summary> /// <returns> /// <c>true</c> if processing the cookies is successfully; otherwise, <c>false</c>. /// </returns> /// <param name="request"> /// A <see cref="CookieCollection"/> that contains a collection of the HTTP Cookies received from the client. /// </param> /// <param name="response"> /// A <see cref="CookieCollection"/> that contains a collection of the HTTP Cookies to send to the client. /// </param> protected virtual bool ProcessCookies(CookieCollection request, CookieCollection response) { return true; }
internal void SetOrRemove (CookieCollection cookies) { foreach (Cookie cookie in cookies) SetOrRemove (cookie); }
private WebSocket() { _cookies = new CookieCollection(); _extensions = String.Empty; _forClose = new Object(); _forSend = new Object(); _protocol = String.Empty; _readyState = WsState.CONNECTING; }
public void SetCookies (CookieCollection cookies) { if (cookies == null || cookies.Count == 0) return; var headers = Headers; foreach (var cookie in cookies.Sorted) headers.Add ("Set-Cookie", cookie.ToResponseString ()); }
public void SetCookies(CookieCollection cookies) { if (cookies.IsNull() || cookies.Count == 0) return; foreach (var cookie in cookies.Sorted) AddHeader("Set-Cookie", cookie.ToResponseString()); }
private void init() { _compression = CompressionMethod.None; _cookies = new CookieCollection (); _forConn = new object (); _forSend = new object (); _readyState = WebSocketState.Connecting; }
public void SetCookies (CookieCollection cookies) { if (cookies == null || cookies.Count == 0) return; var buff = new StringBuilder (64); foreach (var cookie in cookies.Sorted) if (!cookie.Expired) buff.AppendFormat ("{0}; ", cookie.ToString ()); var len = buff.Length; if (len > 2) { buff.Length = len - 2; Headers["Cookie"] = buff.ToString (); } }
private void init () { _compression = CompressionMethod.None; _cookies = new CookieCollection (); _forConn = new object (); _forEvent = new object (); _forSend = new object (); _messageEventQueue = new Queue<MessageEventArgs> (); _forMessageEventQueue = ((ICollection) _messageEventQueue).SyncRoot; _readyState = WebSocketState.Connecting; }
private void init() { _compression = CompressionMethod.NONE; _cookies = new CookieCollection (); _forConn = new object (); _forSend = new object (); _readyState = WebSocketState.CONNECTING; }
private WebSocket() { _compression = CompressionMethod.NONE; _cookies = new CookieCollection (); _extensions = String.Empty; _forClose = new object (); _forSend = new object (); _origin = String.Empty; _preAuth = false; _protocol = String.Empty; _readyState = WebSocketState.CONNECTING; }
private static CookieCollection parseRequest(string value) { var ret = new CookieCollection(); Cookie cookie = null; var ver = 0; var caseInsensitive = StringComparison.InvariantCultureIgnoreCase; var pairs = value.SplitHeaderValue(',', ';').ToList(); for (var i = 0; i < pairs.Count; i++) { var pair = pairs[i].Trim(); if (pair.Length == 0) { continue; } var idx = pair.IndexOf('='); if (idx == -1) { if (cookie == null) { continue; } if (pair.Equals("$port", caseInsensitive)) { cookie.Port = "\"\""; continue; } continue; } if (idx == 0) { if (cookie != null) { ret.add(cookie); cookie = null; } continue; } var name = pair.Substring(0, idx).TrimEnd(' '); var val = idx < pair.Length - 1 ? pair.Substring(idx + 1).TrimStart(' ') : String.Empty; if (name.Equals("$version", caseInsensitive)) { if (val.Length == 0) { continue; } int num; if (!Int32.TryParse(val.Unquote(), out num)) { continue; } ver = num; continue; } if (name.Equals("$path", caseInsensitive)) { if (cookie == null) { continue; } if (val.Length == 0) { continue; } cookie.Path = val; continue; } if (name.Equals("$domain", caseInsensitive)) { if (cookie == null) { continue; } if (val.Length == 0) { continue; } cookie.Domain = val; continue; } if (name.Equals("$port", caseInsensitive)) { if (cookie == null) { continue; } if (val.Length == 0) { continue; } cookie.Port = val; continue; } if (cookie != null) { ret.add(cookie); } if (!Cookie.TryCreate(name, val, out cookie)) { continue; } if (ver != 0) { cookie.Version = ver; } } if (cookie != null) { ret.add(cookie); } return(ret); }