Fix for initializing in HttpListenerRequest.cs
This commit is contained in:
parent
74b8bb392c
commit
56790b683e
@ -275,10 +275,10 @@ namespace WebSocketSharp.Net
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (conn.processInput (conn._requestBuffer.GetBuffer ())) {
|
if (conn.processInput (conn._requestBuffer.GetBuffer ())) {
|
||||||
if (!conn._context.HasError) {
|
if (!conn._context.HasError)
|
||||||
conn._context.Request.FinishInitialization ();
|
conn._context.Request.FinishInitialization ();
|
||||||
}
|
|
||||||
else {
|
if (conn._context.HasError) {
|
||||||
conn.SendError ();
|
conn.SendError ();
|
||||||
conn.Close (true);
|
conn.Close (true);
|
||||||
|
|
||||||
|
@ -78,8 +78,8 @@ namespace WebSocketSharp.Net
|
|||||||
private bool _keepAliveWasSet;
|
private bool _keepAliveWasSet;
|
||||||
private string _method;
|
private string _method;
|
||||||
private NameValueCollection _queryString;
|
private NameValueCollection _queryString;
|
||||||
private string _rawUrl;
|
|
||||||
private Uri _referer;
|
private Uri _referer;
|
||||||
|
private string _uri;
|
||||||
private Uri _url;
|
private Uri _url;
|
||||||
private string [] _userLanguages;
|
private string [] _userLanguages;
|
||||||
private Version _version;
|
private Version _version;
|
||||||
@ -94,7 +94,6 @@ namespace WebSocketSharp.Net
|
|||||||
_contentLength = -1;
|
_contentLength = -1;
|
||||||
_headers = new WebHeaderCollection ();
|
_headers = new WebHeaderCollection ();
|
||||||
_identifier = Guid.NewGuid ();
|
_identifier = Guid.NewGuid ();
|
||||||
_version = HttpVersion.Version10;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -106,7 +105,7 @@ namespace WebSocketSharp.Net
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// An array of <see cref="string"/> that contains the media type names in the Accept
|
/// An array of <see cref="string"/> that contains the media type names in the Accept
|
||||||
/// request-header or <see langword="null"/> if the request didn't include an Accept header.
|
/// request-header, or <see langword="null"/> if the request didn't include an Accept header.
|
||||||
/// </value>
|
/// </value>
|
||||||
public string [] AcceptTypes {
|
public string [] AcceptTypes {
|
||||||
get {
|
get {
|
||||||
@ -123,24 +122,17 @@ namespace WebSocketSharp.Net
|
|||||||
public int ClientCertificateError {
|
public int ClientCertificateError {
|
||||||
get {
|
get {
|
||||||
// TODO: Always returns 0.
|
// TODO: Always returns 0.
|
||||||
/*
|
|
||||||
if (no_get_certificate)
|
|
||||||
throw new InvalidOperationException (
|
|
||||||
"Call GetClientCertificate method before accessing this property.");
|
|
||||||
|
|
||||||
return client_cert_error;
|
|
||||||
*/
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the encoding used with the entity body data included in the request.
|
/// Gets the encoding for the entity body data included in the request.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// A <see cref="Encoding"/> that represents the encoding used with the entity body data or
|
/// A <see cref="Encoding"/> that represents the encoding for the entity body data, or
|
||||||
/// <see cref="Encoding.Default"/> if the request didn't include the information about the
|
/// <see cref="Encoding.Default"/> if the request didn't include the information about
|
||||||
/// encoding.
|
/// the encoding.
|
||||||
/// </value>
|
/// </value>
|
||||||
public Encoding ContentEncoding {
|
public Encoding ContentEncoding {
|
||||||
get {
|
get {
|
||||||
@ -282,7 +274,7 @@ namespace WebSocketSharp.Net
|
|||||||
public bool IsWebSocketRequest {
|
public bool IsWebSocketRequest {
|
||||||
get {
|
get {
|
||||||
return _method == "GET" &&
|
return _method == "GET" &&
|
||||||
_version >= HttpVersion.Version11 &&
|
_version > HttpVersion.Version10 &&
|
||||||
_headers.Contains ("Upgrade", "websocket") &&
|
_headers.Contains ("Upgrade", "websocket") &&
|
||||||
_headers.Contains ("Connection", "Upgrade");
|
_headers.Contains ("Connection", "Upgrade");
|
||||||
}
|
}
|
||||||
@ -297,12 +289,10 @@ namespace WebSocketSharp.Net
|
|||||||
public bool KeepAlive {
|
public bool KeepAlive {
|
||||||
get {
|
get {
|
||||||
if (!_keepAliveWasSet) {
|
if (!_keepAliveWasSet) {
|
||||||
_keepAlive = _headers.Contains ("Connection", "keep-alive") ||
|
string keepAlive;
|
||||||
_version == HttpVersion.Version11
|
_keepAlive = _version > HttpVersion.Version10 ||
|
||||||
? true
|
_headers.Contains ("Connection", "keep-alive") ||
|
||||||
: _headers.Contains ("Keep-Alive")
|
((keepAlive = _headers ["Keep-Alive"]) != null && keepAlive != "closed");
|
||||||
? !_headers.Contains ("Keep-Alive", "closed")
|
|
||||||
: false;
|
|
||||||
|
|
||||||
_keepAliveWasSet = true;
|
_keepAliveWasSet = true;
|
||||||
}
|
}
|
||||||
@ -336,15 +326,15 @@ namespace WebSocketSharp.Net
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the collection of query string variables used in the request.
|
/// Gets the query string included in the request.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// A <see cref="NameValueCollection"/> that contains the collection of query string variables
|
/// A <see cref="NameValueCollection"/> that contains the query string parameters
|
||||||
/// used in the request.
|
/// included in the request.
|
||||||
/// </value>
|
/// </value>
|
||||||
public NameValueCollection QueryString {
|
public NameValueCollection QueryString {
|
||||||
get {
|
get {
|
||||||
return _queryString;
|
return _queryString ?? (_queryString = createQueryString (_url.Query));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -356,7 +346,7 @@ namespace WebSocketSharp.Net
|
|||||||
/// </value>
|
/// </value>
|
||||||
public string RawUrl {
|
public string RawUrl {
|
||||||
get {
|
get {
|
||||||
return _rawUrl;
|
return _url.PathAndQuery;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -400,8 +390,8 @@ namespace WebSocketSharp.Net
|
|||||||
/// Gets the URL of the resource from which the requested URL was obtained.
|
/// Gets the URL of the resource from which the requested URL was obtained.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// A <see cref="Uri"/> that represents the value of the Referer request-header or
|
/// A <see cref="Uri"/> that represents the value of the Referer request-header,
|
||||||
/// <see langword="null"/> if the request didn't include an Referer header.
|
/// or <see langword="null"/> if the request didn't include an Referer header.
|
||||||
/// </value>
|
/// </value>
|
||||||
public Uri UrlReferrer {
|
public Uri UrlReferrer {
|
||||||
get {
|
get {
|
||||||
@ -449,9 +439,9 @@ namespace WebSocketSharp.Net
|
|||||||
/// Gets the natural languages which are preferred for the response.
|
/// Gets the natural languages which are preferred for the response.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// An array of <see cref="string"/> that contains the natural language names in the
|
/// An array of <see cref="string"/> that contains the natural language names in
|
||||||
/// Accept-Language request-header or <see langword="null"/> if the request didn't
|
/// the Accept-Language request-header, or <see langword="null"/> if the request
|
||||||
/// include an Accept-Language header.
|
/// didn't include an Accept-Language header.
|
||||||
/// </value>
|
/// </value>
|
||||||
public string [] UserLanguages {
|
public string [] UserLanguages {
|
||||||
get {
|
get {
|
||||||
@ -579,24 +569,27 @@ namespace WebSocketSharp.Net
|
|||||||
host = UserHostAddress;
|
host = UserHostAddress;
|
||||||
|
|
||||||
string path = null;
|
string path = null;
|
||||||
if (_rawUrl.StartsWith ("/")) {
|
if (_uri.StartsWith ("/")) {
|
||||||
path = HttpUtility.UrlDecode (_rawUrl);
|
path = HttpUtility.UrlDecode (_uri);
|
||||||
}
|
}
|
||||||
else if (_rawUrl.MaybeUri ()) {
|
else if (_uri.MaybeUri ()) {
|
||||||
if (!Uri.TryCreate (_rawUrl, UriKind.Absolute, out _url) ||
|
Uri uri;
|
||||||
!(_url.Scheme.StartsWith ("http") || _url.Scheme.StartsWith ("ws"))) {
|
if (!Uri.TryCreate (_uri, UriKind.Absolute, out uri) ||
|
||||||
_context.ErrorMessage = "Invalid request url: " + _rawUrl;
|
!(uri.Scheme.StartsWith ("http") || uri.Scheme.StartsWith ("ws"))) {
|
||||||
|
_context.ErrorMessage = "Invalid request url: " + _uri;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
host = uri.Authority;
|
||||||
|
path = uri.PathAndQuery;
|
||||||
}
|
}
|
||||||
else if (_rawUrl == "*") {
|
else if (_uri == "*") {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// As authority form
|
// As authority form
|
||||||
host = HttpUtility.UrlDecode (_rawUrl);
|
host = HttpUtility.UrlDecode (_uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_url == null) {
|
|
||||||
var scheme = IsWebSocketRequest ? "ws" : "http";
|
var scheme = IsWebSocketRequest ? "ws" : "http";
|
||||||
var secure = IsSecureConnection;
|
var secure = IsSecureConnection;
|
||||||
if (secure)
|
if (secure)
|
||||||
@ -611,12 +604,9 @@ namespace WebSocketSharp.Net
|
|||||||
_context.ErrorMessage = "Invalid request url: " + url;
|
_context.ErrorMessage = "Invalid request url: " + url;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
_queryString = createQueryString (_url.Query);
|
|
||||||
|
|
||||||
var encoding = Headers ["Transfer-Encoding"];
|
var encoding = Headers ["Transfer-Encoding"];
|
||||||
if (_version >= HttpVersion.Version11 && encoding != null && encoding.Length > 0) {
|
if (_version > HttpVersion.Version10 && encoding != null && encoding.Length > 0) {
|
||||||
_chunked = encoding.ToLower () == "chunked";
|
_chunked = encoding.ToLower () == "chunked";
|
||||||
if (!_chunked) {
|
if (!_chunked) {
|
||||||
_context.ErrorMessage = String.Empty;
|
_context.ErrorMessage = String.Empty;
|
||||||
@ -684,7 +674,7 @@ namespace WebSocketSharp.Net
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_rawUrl = parts [1];
|
_uri = parts [1];
|
||||||
|
|
||||||
if (parts [2].Length != 8 ||
|
if (parts [2].Length != 8 ||
|
||||||
!parts [2].StartsWith ("HTTP/") ||
|
!parts [2].StartsWith ("HTTP/") ||
|
||||||
@ -773,7 +763,7 @@ namespace WebSocketSharp.Net
|
|||||||
public override string ToString ()
|
public override string ToString ()
|
||||||
{
|
{
|
||||||
var buff = new StringBuilder (64);
|
var buff = new StringBuilder (64);
|
||||||
buff.AppendFormat ("{0} {1} HTTP/{2}\r\n", _method, _rawUrl, _version);
|
buff.AppendFormat ("{0} {1} HTTP/{2}\r\n", _method, _uri, _version);
|
||||||
buff.Append (_headers.ToString ());
|
buff.Append (_headers.ToString ());
|
||||||
|
|
||||||
return buff.ToString ();
|
return buff.ToString ();
|
||||||
|
Loading…
Reference in New Issue
Block a user