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

Commit 4e191a3

Browse files
committed
Clean up
1 parent 91b81c9 commit 4e191a3

File tree

6 files changed

+16
-49
lines changed

6 files changed

+16
-49
lines changed

samples/ResponseCachingSample/Startup.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public void ConfigureServices(IServiceCollection services)
2020

2121
public void Configure(IApplicationBuilder app)
2222
{
23-
app.UseDeveloperExceptionPage();
2423
app.UseResponseCaching();
2524
app.Run(async (context) =>
2625
{
@@ -30,7 +29,7 @@ public void Configure(IApplicationBuilder app)
3029
Public = true,
3130
MaxAge = TimeSpan.FromSeconds(10)
3231
};
33-
context.Response.GetTypedHeaders().Append("Vary", "Accept-Language");
32+
context.Response.GetTypedHeaders().AppendList("Vary", new string[] { "Accept-Encoding", "Non-Existent" });
3433

3534
await context.Response.WriteAsync("Hello World! " + DateTime.UtcNow);
3635
});

samples/ResponseCachingSample/project.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"version": "1.1.0-*",
33
"dependencies": {
4-
"Microsoft.AspNetCore.Diagnostics": "0.1.0-*",
54
"Microsoft.AspNetCore.ResponseCaching": "0.1.0-*",
65
"Microsoft.AspNetCore.Server.IISIntegration": "1.1.0-*",
76
"Microsoft.AspNetCore.Server.Kestrel": "1.1.0-*",
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using Microsoft.Extensions.Primitives;
5+
46
namespace Microsoft.AspNetCore.ResponseCaching
57
{
68
public class CachedVaryBy : IResponseCacheEntry
@@ -9,8 +11,6 @@ public class CachedVaryBy : IResponseCacheEntry
911

1012
public ResponseCacheEntryType Type => ResponseCacheEntryType.VaryBy;
1113

12-
public string[] Headers { get; set; }
13-
14-
public string[] Params { get; set; }
14+
public StringValues Headers { get; set; }
1515
}
1616
}

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

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -86,23 +86,9 @@ private static IResponseCacheEntry ReadCachedResponse(BinaryReader reader)
8686

8787
private static IResponseCacheEntry ReadCachedVaryBy(BinaryReader reader)
8888
{
89-
var headerCount = reader.ReadInt32();
90-
var headerArray = new string[headerCount];
91-
for (var index = 0; index < headerCount; index++)
92-
{
93-
var value = reader.ReadString();
94-
headerArray[index] = value;
95-
}
89+
var headers = reader.ReadString().Split(',');
9690

97-
var paramCount = reader.ReadInt32();
98-
var paramArray = new string[paramCount];
99-
for (var index = 0; index < paramCount; index++)
100-
{
101-
var value = reader.ReadString();
102-
paramArray[index] = value;
103-
}
104-
105-
return new CachedVaryBy { Headers = headerArray, Params = paramArray };
91+
return new CachedVaryBy { Headers = headers };
10692
}
10793

10894
public static void Write(BinaryWriter writer, IResponseCacheEntry entry)
@@ -147,30 +133,7 @@ private static void WriteCachedResponse(BinaryWriter writer, CachedResponse entr
147133

148134
private static void WriteCachedVaryBy(BinaryWriter writer, CachedVaryBy entry)
149135
{
150-
if (entry.Headers == null)
151-
{
152-
writer.Write(0);
153-
}
154-
else
155-
{
156-
writer.Write(entry.Headers.Length);
157-
foreach (var header in entry.Headers)
158-
{
159-
writer.Write(header);
160-
}
161-
}
162-
if (entry.Params == null)
163-
{
164-
writer.Write(0);
165-
}
166-
else
167-
{
168-
writer.Write(entry.Params.Length);
169-
foreach (var param in entry.Params)
170-
{
171-
writer.Write(param);
172-
}
173-
}
136+
writer.Write(entry.Headers);
174137
}
175138
}
176139
}

src/Microsoft.AspNetCore.ResponseCaching/ResponseCachingContext.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,17 @@ private string CreateVaryByCacheKey(CachedVaryBy varyBy)
8383

8484
foreach (var header in varyBy.Headers)
8585
{
86+
var value = request.Headers[header].ToString();
87+
// null vs Empty?
88+
if (string.IsNullOrEmpty(value))
89+
{
90+
value = "null";
91+
}
92+
8693
builder.Append(header)
8794
.Append("=")
88-
.Append(request.Headers[header].ToString() ?? "null") // null vs Empty?
89-
.Append(",");
95+
.Append(value)
96+
.Append(";");
9097
}
9198

9299
// Parse querystring params

src/Microsoft.AspNetCore.ResponseCaching/ResponseCachingExtensions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ public static class ResponseCachingExtensions
99
{
1010
public static IApplicationBuilder UseResponseCaching(this IApplicationBuilder app)
1111
{
12-
1312
return app.UseMiddleware<ResponseCachingMiddleware>();
1413
}
1514
}

0 commit comments

Comments
 (0)