Skip to content

Commit

Permalink
1.0.32
Browse files Browse the repository at this point in the history
  • Loading branch information
Thorium committed Nov 23, 2022
1 parent 1141270 commit e206617
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 31 deletions.
2 changes: 1 addition & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### 1.0.31 - November 23 2022
### 1.0.32 - November 23 2022
* Improvements on error handling
* Improvements on picking which files to compress

Expand Down
8 changes: 4 additions & 4 deletions src/Owin.Compression.Standard/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ open System.Reflection
[<assembly: AssemblyTitleAttribute("Owin.Compression.Standard")>]
[<assembly: AssemblyProductAttribute("Owin.Compression")>]
[<assembly: AssemblyDescriptionAttribute("Compression (Deflate / GZip) module for Microsoft OWIN Selfhost filesystem pipeline.")>]
[<assembly: AssemblyVersionAttribute("1.0.31")>]
[<assembly: AssemblyFileVersionAttribute("1.0.31")>]
[<assembly: AssemblyVersionAttribute("1.0.32")>]
[<assembly: AssemblyFileVersionAttribute("1.0.32")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "Owin.Compression.Standard"
let [<Literal>] AssemblyProduct = "Owin.Compression"
let [<Literal>] AssemblyDescription = "Compression (Deflate / GZip) module for Microsoft OWIN Selfhost filesystem pipeline."
let [<Literal>] AssemblyVersion = "1.0.31"
let [<Literal>] AssemblyFileVersion = "1.0.31"
let [<Literal>] AssemblyVersion = "1.0.32"
let [<Literal>] AssemblyFileVersion = "1.0.32"
38 changes: 28 additions & 10 deletions src/Owin.Compression.Standard/CompressionModule.fs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ module OwinCompression =
| ContextResponseBody(next) ->


let compressableExtension() =
let compressableExtension() =
match context.Request.Path.ToString() with
| null -> true
| x when x.Contains(".") ->
Expand All @@ -262,15 +262,19 @@ module OwinCompression =
else

let compressableExtension = compressableExtension()
let isCompressable = compressableExtension && not(context.Request.Path.ToString().Contains("/signalr/"))

let continuation1 bufferData =
let checkCompressability buffer =
let captureResponse() =
match buffer with
| Some bufferStream ->
context.Response.Body <- bufferStream
| None -> ()
if compressableExtension then // non-stream, but Invoke can change "/" -> "index.html"
context.Response.Body <- bufferData
captureResponse()
true
elif String.IsNullOrEmpty context.Response.ContentType then
elif String.IsNullOrEmpty context.Response.ContentType then
if settings.AllowUnknonwnFiletypes then
context.Response.Body <- bufferData
captureResponse()
true
else false
else
Expand All @@ -282,11 +286,15 @@ module OwinCompression =
if settings.AllowedExtensionAndMimeTypes
|> Seq.map snd |> Seq.append ["text/html"]
|> Seq.contains(contentType) then
context.Response.Body <- bufferData
captureResponse()
true
else
false

let isCompressable =
(checkCompressability None) && not(context.Request.Path.ToString().Contains("/signalr/"))
&& context.Response.Body.CanWrite

let continuation2 (copy1:unit->Task) (copy2:Stream->Task) (copy3:MemoryStream->Task) =
task {

Expand Down Expand Up @@ -355,13 +363,23 @@ module OwinCompression =
context.Response.Body <- buffer // stream
else
()
let usecompress = isCompressable || continuation1 buffer

do! next.Invoke()

let usecompress = isCompressable || checkCompressability (Some buffer)

if usecompress && checkNoValidETag(context.Response.Body) then
let copy1() = context.Response.Body.CopyToAsync(streamWebOutput, defaultBufferSize, cancellationToken)
let copy1() =
task {
do! context.Response.Body.CopyToAsync(streamWebOutput, defaultBufferSize, cancellationToken)
context.Response.Body <- streamWebOutput
} :> Task
let copy2 (zipped:Stream) = context.Response.Body.CopyToAsync(zipped, defaultBufferSize, cancellationToken)
let copy3 (zippedData:MemoryStream) = zippedData.CopyToAsync(streamWebOutput, defaultBufferSize, cancellationToken)
let copy3 (zippedData:MemoryStream) =
task {
do! zippedData.CopyToAsync(streamWebOutput, defaultBufferSize, cancellationToken)
context.Response.Body <- streamWebOutput
} :> Task
return! continuation2 copy1 copy2 copy3
else
return ()
Expand Down
8 changes: 4 additions & 4 deletions src/Owin.Compression/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ open System.Reflection
[<assembly: AssemblyTitleAttribute("Owin.Compression")>]
[<assembly: AssemblyProductAttribute("Owin.Compression")>]
[<assembly: AssemblyDescriptionAttribute("Compression (Deflate / GZip) module for Microsoft OWIN Selfhost filesystem pipeline.")>]
[<assembly: AssemblyVersionAttribute("1.0.31")>]
[<assembly: AssemblyFileVersionAttribute("1.0.31")>]
[<assembly: AssemblyVersionAttribute("1.0.32")>]
[<assembly: AssemblyFileVersionAttribute("1.0.32")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "Owin.Compression"
let [<Literal>] AssemblyProduct = "Owin.Compression"
let [<Literal>] AssemblyDescription = "Compression (Deflate / GZip) module for Microsoft OWIN Selfhost filesystem pipeline."
let [<Literal>] AssemblyVersion = "1.0.31"
let [<Literal>] AssemblyFileVersion = "1.0.31"
let [<Literal>] AssemblyVersion = "1.0.32"
let [<Literal>] AssemblyFileVersion = "1.0.32"
33 changes: 24 additions & 9 deletions src/Owin.Compression/CompressionModule.fs
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,19 @@ module OwinCompression =
else

let compressableExtension = compressableExtension()
let isCompressable = compressableExtension && not(context.Request.Path.ToString().Contains("/signalr/"))

let continuation1 bufferData =
let checkCompressability buffer =
let captureResponse() =
match buffer with
| Some bufferStream ->
context.Response.Body <- bufferStream
| None -> ()
if compressableExtension then // non-stream, but Invoke can change "/" -> "index.html"
context.Response.Body <- bufferData
captureResponse()
true
elif String.IsNullOrEmpty context.Response.ContentType then
if settings.AllowUnknonwnFiletypes then
context.Response.Body <- bufferData
captureResponse()
true
else false
else
Expand All @@ -273,11 +277,15 @@ module OwinCompression =
if settings.AllowedExtensionAndMimeTypes
|> Seq.map snd |> Seq.append ["text/html"]
|> Seq.contains(contentType) then
context.Response.Body <- bufferData
captureResponse()
true
else
false

let isCompressable =
(checkCompressability None) && not(context.Request.Path.ToString().Contains("/signalr/"))
&& context.Response.Body.CanWrite

let continuation2 (copy1:unit->Task) (copy2:Stream->Task) (copy3:MemoryStream->Task) =
task {

Expand Down Expand Up @@ -349,15 +357,22 @@ module OwinCompression =
else
()

let usecompress = isCompressable || continuation1 buffer
do! next.Invoke()

let usecompress = isCompressable || checkCompressability (Some buffer)
if usecompress && checkNoValidETag(context.Response.Body) then

let copy1() = context.Response.Body.CopyToAsync(streamWebOutput, defaultBufferSize, cancellationToken)
let copy1() =
task {
do! context.Response.Body.CopyToAsync(streamWebOutput, defaultBufferSize, cancellationToken)
context.Response.Body <- streamWebOutput
} :> Task
let copy2 (zipped:Stream) = context.Response.Body.CopyToAsync(zipped, defaultBufferSize, cancellationToken)
let copy3 (zippedData:MemoryStream) = zippedData.CopyToAsync(streamWebOutput, defaultBufferSize, cancellationToken)

let copy3 (zippedData:MemoryStream) =
task {
do! zippedData.CopyToAsync(streamWebOutput, defaultBufferSize, cancellationToken)
context.Response.Body <- streamWebOutput
} :> Task
return! continuation2 copy1 copy2 copy3

else
Expand Down
6 changes: 3 additions & 3 deletions tests/Aspnet.Core.WebAPI.Test/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ module Program =

let app = builder.Build()

let weba = app :> IApplicationBuilder
let compressionSetting =
{OwinCompression.DefaultCompressionSettings with
CacheExpireTime = Some (DateTimeOffset.Now.AddDays 7.)
Expand All @@ -36,9 +35,10 @@ module Program =
MinimumSizeToCompress = 0
}

weba.UseCompressionModule(compressionSetting) |> ignore
app.MapControllers()
(app :> IApplicationBuilder).UseCompressionModule(compressionSetting) |> ignore

app.MapControllers()

app.Run()

exitCode

0 comments on commit e206617

Please sign in to comment.