Implement request and response properties: Headers, ContentLength.
This commit is contained in:
parent
86025a3ec4
commit
850128dc39
|
|
@ -9,8 +9,10 @@ namespace Microsoft.AspNet.Abstractions
|
|||
|
||||
public abstract HttpContext HttpContext { get; }
|
||||
public abstract int StatusCode { get; set; }
|
||||
public abstract IHeaderDictionary Headers { get; }
|
||||
public abstract Stream Body { get; set; }
|
||||
|
||||
public abstract long? ContentLength { get; set; }
|
||||
public abstract string ContentType { get; set; }
|
||||
|
||||
public abstract Task WriteAsync(string data);
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using Microsoft.AspNet.Abstractions;
|
||||
using Microsoft.AspNet.FeatureModel;
|
||||
using Microsoft.AspNet.HttpFeature;
|
||||
using Microsoft.AspNet.PipelineCore.Collections;
|
||||
using Microsoft.AspNet.PipelineCore.Infrastructure;
|
||||
|
||||
namespace Microsoft.AspNet.PipelineCore
|
||||
|
|
@ -118,7 +120,7 @@ namespace Microsoft.AspNet.PipelineCore
|
|||
|
||||
public override IHeaderDictionary Headers
|
||||
{
|
||||
get { throw new NotImplementedException(); }
|
||||
get { return new HeaderDictionary(HttpRequestInformation.Headers); }
|
||||
}
|
||||
|
||||
public override IReadableStringCollection Cookies
|
||||
|
|
@ -130,7 +132,8 @@ namespace Microsoft.AspNet.PipelineCore
|
|||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return CancellationToken.None;
|
||||
// throw new NotImplementedException();
|
||||
}
|
||||
set
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
using System.IO;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Abstractions;
|
||||
using Microsoft.AspNet.Abstractions.Infrastructure;
|
||||
using Microsoft.AspNet.FeatureModel;
|
||||
using Microsoft.AspNet.HttpFeature;
|
||||
using Microsoft.AspNet.PipelineCore.Collections;
|
||||
using Microsoft.AspNet.PipelineCore.Infrastructure;
|
||||
|
||||
namespace Microsoft.AspNet.PipelineCore
|
||||
|
|
@ -33,22 +36,63 @@ namespace Microsoft.AspNet.PipelineCore
|
|||
set { HttpResponseInformation.StatusCode = value; }
|
||||
}
|
||||
|
||||
public override IHeaderDictionary Headers
|
||||
{
|
||||
get { return new HeaderDictionary(HttpResponseInformation.Headers); }
|
||||
}
|
||||
|
||||
public override Stream Body
|
||||
{
|
||||
get { return HttpResponseInformation.Body; }
|
||||
set { HttpResponseInformation.Body = value; }
|
||||
}
|
||||
|
||||
public override long? ContentLength
|
||||
{
|
||||
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))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value.HasValue)
|
||||
{
|
||||
HttpResponseInformation.Headers[Constants.Headers.ContentLength] =
|
||||
new[] { value.Value.ToString(CultureInfo.InvariantCulture) };
|
||||
}
|
||||
else
|
||||
{
|
||||
HttpResponseInformation.Headers.Remove(Constants.Headers.ContentLength);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override string ContentType
|
||||
{
|
||||
get
|
||||
{
|
||||
var contentTypeValues = HttpResponseInformation.Headers["Content-Type"];
|
||||
var contentTypeValues = HttpResponseInformation.Headers[Constants.Headers.ContentType];
|
||||
return contentTypeValues.Length == 0 ? null : contentTypeValues[0];
|
||||
}
|
||||
set
|
||||
{
|
||||
HttpResponseInformation.Headers["Content-Type"] = new[] { value };
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
HttpResponseInformation.Headers.Remove(Constants.Headers.ContentType);
|
||||
}
|
||||
else
|
||||
{
|
||||
HttpResponseInformation.Headers[Constants.Headers.ContentType] = new[] { value };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue