#79: Remove cookie compression.

This commit is contained in:
Chris Ross 2014-12-05 10:40:46 -08:00
parent 0a71973513
commit 184233af61
4 changed files with 6 additions and 33 deletions

View File

@ -36,7 +36,7 @@ namespace Microsoft.AspNet.Security.Cookies
if (Options.TicketDataFormat == null) if (Options.TicketDataFormat == null)
{ {
IDataProtector dataProtector = dataProtectionProvider.CreateDataProtector( IDataProtector dataProtector = dataProtectionProvider.CreateDataProtector(
typeof(CookieAuthenticationMiddleware).FullName, Options.AuthenticationType, "v1"); typeof(CookieAuthenticationMiddleware).FullName, Options.AuthenticationType, "v2");
Options.TicketDataFormat = new TicketDataFormat(dataProtector); Options.TicketDataFormat = new TicketDataFormat(dataProtector);
} }
if (Options.CookieManager == null) if (Options.CookieManager == null)

View File

@ -26,7 +26,6 @@
"System.Dynamic.Runtime": "4.0.0-beta-*", "System.Dynamic.Runtime": "4.0.0-beta-*",
"System.Globalization": "4.0.10-beta-*", "System.Globalization": "4.0.10-beta-*",
"System.IO": "4.0.10-beta-*", "System.IO": "4.0.10-beta-*",
"System.IO.Compression": "4.0.0-beta-*",
"System.Linq": "4.0.0-beta-*", "System.Linq": "4.0.0-beta-*",
"System.Net.Http.WinHttpHandler": "4.0.0-beta-*", "System.Net.Http.WinHttpHandler": "4.0.0-beta-*",
"System.ObjectModel": "4.0.10-beta-*", "System.ObjectModel": "4.0.10-beta-*",

View File

@ -1,11 +1,8 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.IO.Compression;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
@ -13,46 +10,27 @@ namespace Microsoft.AspNet.Security.DataHandler.Serializer
{ {
public class TicketSerializer : IDataSerializer<AuthenticationTicket> public class TicketSerializer : IDataSerializer<AuthenticationTicket>
{ {
private static readonly bool IsMono = Type.GetType("Mono.Runtime") != null;
private const int FormatVersion = 2; private const int FormatVersion = 2;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2202:Do not dispose objects multiple times", Justification = "Dispose is idempotent")]
public virtual byte[] Serialize(AuthenticationTicket model) public virtual byte[] Serialize(AuthenticationTicket model)
{ {
using (var memory = new MemoryStream()) using (var memory = new MemoryStream())
{ {
GZipStream compression; using (var writer = new BinaryWriter(memory))
if (IsMono)
{ {
// The other constructor is not currently supported on Mono. Write(writer, model);
compression = new GZipStream(memory, CompressionMode.Compress);
}
else
{
compression = new GZipStream(memory, CompressionLevel.Optimal);
}
using (compression)
{
using (var writer = new BinaryWriter(compression))
{
Write(writer, model);
}
} }
return memory.ToArray(); return memory.ToArray();
} }
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2202:Do not dispose objects multiple times", Justification = "Dispose is idempotent")]
public virtual AuthenticationTicket Deserialize(byte[] data) public virtual AuthenticationTicket Deserialize(byte[] data)
{ {
using (var memory = new MemoryStream(data)) using (var memory = new MemoryStream(data))
{ {
using (var compression = new GZipStream(memory, CompressionMode.Decompress)) using (var reader = new BinaryReader(memory))
{ {
using (var reader = new BinaryReader(compression)) return Read(reader);
{
return Read(reader);
}
} }
} }
} }

View File

@ -10,10 +10,6 @@
}, },
"frameworks": { "frameworks": {
"aspnet50": { }, "aspnet50": { },
"aspnetcore50": { "aspnetcore50": { }
"dependencies": {
"System.IO.Compression": "4.0.0-beta-*"
}
}
} }
} }