From fe1011e50713732a608a3be1e766986b0115684c Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Mon, 10 Feb 2014 10:52:19 -0800 Subject: [PATCH] Code review cleanup. --- .../OwinHttpEnvironment.cs | 26 ++++++++++++++++--- .../DefaultHttpRequest.cs | 2 +- .../DefaultHttpResponse.cs | 6 ++--- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.AspNet.AppBuilderSupport/OwinHttpEnvironment.cs b/src/Microsoft.AspNet.AppBuilderSupport/OwinHttpEnvironment.cs index b03c9bd7fe..02be7db4a5 100644 --- a/src/Microsoft.AspNet.AppBuilderSupport/OwinHttpEnvironment.cs +++ b/src/Microsoft.AspNet.AppBuilderSupport/OwinHttpEnvironment.cs @@ -169,7 +169,7 @@ namespace Microsoft.AspNet.PipelineCore.Owin object obj; if (Environment.TryGetValue(OwinConstants.SendFiles.SendAsync, out obj)) { - SendFileFunc func = (SendFileFunc)obj; + var func = (SendFileFunc)obj; return func(path, offset, length, cancellation); } throw new NotSupportedException(OwinConstants.SendFiles.SendAsync); @@ -237,7 +237,7 @@ namespace Microsoft.AspNet.PipelineCore.Owin { get { - IList keys = new List() + var keys = new List() { typeof(IHttpRequestInformation), typeof(IHttpResponseInformation), @@ -306,12 +306,30 @@ namespace Microsoft.AspNet.PipelineCore.Owin public bool Contains(KeyValuePair item) { - throw new NotImplementedException(); + object result; + return TryGetValue(item.Key, out result) && result.Equals(item.Value); } public void CopyTo(KeyValuePair[] array, int arrayIndex) { - throw new NotImplementedException(); + if (array == null) + { + throw new ArgumentNullException("array"); + } + if (arrayIndex < 0 || arrayIndex > array.Length) + { + throw new ArgumentOutOfRangeException("arrayIndex", arrayIndex, string.Empty); + } + var keys = Keys; + if (keys.Count > array.Length - arrayIndex) + { + throw new ArgumentException(); + } + + foreach (var key in keys) + { + array[arrayIndex++] = new KeyValuePair(key, this[key]); + } } public int Count diff --git a/src/Microsoft.AspNet.PipelineCore/DefaultHttpRequest.cs b/src/Microsoft.AspNet.PipelineCore/DefaultHttpRequest.cs index ac5e3d7572..0f98a561f1 100644 --- a/src/Microsoft.AspNet.PipelineCore/DefaultHttpRequest.cs +++ b/src/Microsoft.AspNet.PipelineCore/DefaultHttpRequest.cs @@ -132,8 +132,8 @@ namespace Microsoft.AspNet.PipelineCore { get { + // TODO: Which feature exposes this? return CancellationToken.None; - // throw new NotImplementedException(); } set { diff --git a/src/Microsoft.AspNet.PipelineCore/DefaultHttpResponse.cs b/src/Microsoft.AspNet.PipelineCore/DefaultHttpResponse.cs index 5431315cb7..5fec0bc498 100644 --- a/src/Microsoft.AspNet.PipelineCore/DefaultHttpResponse.cs +++ b/src/Microsoft.AspNet.PipelineCore/DefaultHttpResponse.cs @@ -51,11 +51,9 @@ namespace Microsoft.AspNet.PipelineCore { get { - string[] values; long value; - if (HttpResponseInformation.Headers.TryGetValue(Constants.Headers.ContentLength, out values) - && values != null && values.Length > 0 && !string.IsNullOrWhiteSpace(values[0]) - && long.TryParse(values[0], out value)) + string rawValue = Headers.Get(Constants.Headers.ContentLength); + if (!string.IsNullOrWhiteSpace(rawValue) && long.TryParse(rawValue, out value)) { return value; }