Skip to content
This repository was archived by the owner on Nov 22, 2018. It is now read-only.

Commit 4e732b9

Browse files
committed
Feedback
1 parent bd2884d commit 4e732b9

File tree

4 files changed

+28
-47
lines changed

4 files changed

+28
-47
lines changed

src/Microsoft.AspNetCore.ResponseCaching/Internal/DefaultResponseCacheEntrySerializer.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ namespace Microsoft.AspNetCore.ResponseCaching.Internal
1010
internal static class DefaultResponseCacheSerializer
1111
{
1212
private const int FormatVersion = 1;
13-
private const string RoundTripFormat = "o";
1413

1514
public static object Deserialize(byte[] serializedEntry)
1615
{

src/Microsoft.AspNetCore.ResponseCaching/Internal/ResponseCacheStream.cs

Lines changed: 21 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -43,44 +43,21 @@ public void DisableBuffering()
4343

4444
public override void SetLength(long value)
4545
{
46-
try
47-
{
48-
_innerStream.SetLength(value);
49-
if (BufferingEnabled)
50-
{
51-
BufferedStream.SetLength(value);
52-
}
53-
}
54-
catch
55-
{
56-
DisableBuffering();
57-
throw;
58-
}
46+
DisableBuffering();
47+
_innerStream.SetLength(value);
5948
}
6049

6150
public override long Seek(long offset, SeekOrigin origin)
6251
{
63-
try
64-
{
65-
var position = _innerStream.Seek(offset, origin);
66-
if (BufferingEnabled)
67-
{
68-
BufferedStream.Seek(offset, origin);
69-
}
70-
return position;
71-
}
72-
catch
73-
{
74-
DisableBuffering();
75-
throw;
76-
}
52+
DisableBuffering();
53+
return _innerStream.Seek(offset, origin);
7754
}
7855

7956
public override void Flush()
8057
=> _innerStream.Flush();
8158

82-
public override async Task FlushAsync(CancellationToken cancellationToken)
83-
=> await _innerStream.FlushAsync();
59+
public override Task FlushAsync(CancellationToken cancellationToken)
60+
=> _innerStream.FlushAsync();
8461

8562
// Underlying stream is write-only, no need to override other read related methods
8663
public override int Read(byte[] buffer, int offset, int count)
@@ -91,50 +68,53 @@ public override void Write(byte[] buffer, int offset, int count)
9168
try
9269
{
9370
_innerStream.Write(buffer, offset, count);
94-
if (BufferingEnabled)
95-
{
96-
BufferedStream.Write(buffer, offset, count);
97-
}
9871
}
9972
catch
10073
{
10174
DisableBuffering();
10275
throw;
10376
}
77+
78+
if (BufferingEnabled)
79+
{
80+
BufferedStream.Write(buffer, offset, count);
81+
}
10482
}
10583

10684
public override async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
10785
{
10886
try
10987
{
11088
await _innerStream.WriteAsync(buffer, offset, count, cancellationToken);
111-
if (BufferingEnabled)
112-
{
113-
await BufferedStream.WriteAsync(buffer, offset, count, cancellationToken);
114-
}
11589
}
11690
catch
11791
{
11892
DisableBuffering();
11993
throw;
12094
}
95+
96+
if (BufferingEnabled)
97+
{
98+
await BufferedStream.WriteAsync(buffer, offset, count, cancellationToken);
99+
}
121100
}
122101

123102
public override void WriteByte(byte value)
124103
{
125104
try
126105
{
127106
_innerStream.WriteByte(value);
128-
if (BufferingEnabled)
129-
{
130-
BufferedStream.WriteByte(value);
131-
}
132107
}
133108
catch
134109
{
135110
DisableBuffering();
136111
throw;
137112
}
113+
114+
if (BufferingEnabled)
115+
{
116+
BufferedStream.WriteByte(value);
117+
}
138118
}
139119

140120
#if NETSTANDARD1_3

src/Microsoft.AspNetCore.ResponseCaching/Internal/SendFileFeatureWrapper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ public SendFileFeatureWrapper(IHttpSendFileFeature originalSendFileFeature, Resp
1919
}
2020

2121
// Flush and disable the buffer if anyone tries to call the SendFile feature.
22-
public async Task SendFileAsync(string path, long offset, long? length, CancellationToken cancellation)
22+
public Task SendFileAsync(string path, long offset, long? length, CancellationToken cancellation)
2323
{
2424
_responseCacheStream.DisableBuffering();
25-
await _originalSendFileFeature.SendFileAsync(path, offset, length, cancellation);
25+
return _originalSendFileFeature.SendFileAsync(path, offset, length, cancellation);
2626
}
2727
}
2828
}

src/Microsoft.AspNetCore.ResponseCaching/ResponseCachingContext.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ private string CreateVaryByCacheKey(CachedVaryBy varyBy)
183183
return builder.ToString();
184184
}
185185

186-
public bool RequestIsCacheable()
186+
internal bool RequestIsCacheable()
187187
{
188188
// Verify the method
189189
// TODO: RFC lists POST as a cacheable method when explicit freshness information is provided, but this is not widely implemented. Will revisit.
@@ -387,6 +387,10 @@ internal async Task<bool> TryServeFromCacheAsync()
387387

388388
responseServed = true;
389389
}
390+
else
391+
{
392+
throw new InvalidOperationException("Response type not specified or is unrecognized.");
393+
}
390394
}
391395
else
392396
{
@@ -396,7 +400,6 @@ internal async Task<bool> TryServeFromCacheAsync()
396400

397401
if (!responseServed && RequestCacheControl.OnlyIfCached)
398402
{
399-
HttpContext.Response.Clear();
400403
HttpContext.Response.StatusCode = StatusCodes.Status504GatewayTimeout;
401404

402405
responseServed = true;
@@ -467,7 +470,6 @@ internal void FinalizeCachingBody()
467470
{
468471
_cachedResponse.Body = ResponseCacheStream.BufferedStream.ToArray();
469472

470-
// TODO: Timeouts
471473
Cache.Set(_cacheKey, _cachedResponse, _cachedResponseValidFor);
472474
}
473475
}

0 commit comments

Comments
 (0)