Comments (12)
The original idea is simply that if the server calculated value over the content ("body") is the same than client already has in ETAG, we don't need to compress and send the resource over the wire.
from owin.compression.
Hmm... Was the context.Response.Body empty at the time of calculation?
from owin.compression.
Hi,
after some tests, it turned out that the response buffer has the position pointing to the buffer end thus hashing always returns the same results.
So, this part matters
let getMd5Hash (item:Stream) =
item.Position <- 0L
With regards to context.Response.Body - it seems unrelated somehow and probably something to deal with many other middlewares I have.
There is one remark though, you make context.Respones.Body pointing to your buffer and don't restore it before exit. The middleware which executes on top that will try to access context.Response.Body after Next.Invoke might use the incorrect buffer. Not sure if that's a valid concern though.
from owin.compression.
I have not experienced this. So maybe the order of middleware-registration is significant.
from owin.compression.
All right,
but what's with regard to the stream position. Will you make the update to change the position into the beginning of the stream during the MD5 hash calculation?
from owin.compression.
Can you send a PR?
from owin.compression.
Is this only for streams?
from owin.compression.
Yeah, it's for streams. That's our use case. I'm not a F# developer, so I might be doing this the wrong way :)
You might want to check if it's allowed to perform seek operations on the stream. And to position the stream the same way you do in the code below.
from owin.compression.
Should we reset the position back to original,
e.g.
let getMd5Hash (item:Stream) =
let hasPos =
if item.CanSeek && item.Position > 0L then
let tmp = item.Position
item.Position <- 0L
Some tmp
else None
use md5 = System.Security.Cryptography.MD5.Create()
let res = BitConverter.ToString(md5.ComputeHash(item)).Replace("-","")
match hasPos with
| Some x when item.CanSeek -> item.Position <- x
| _ -> ()
res
from owin.compression.
I didn't find any info about whether the middleware must persist the state of the Context.Response.Body stream. So I would assume this is not a requirement, however, it won't harm either :)
from owin.compression.
This is now added to NuGet version 1.1.18. Hopefully helps.
from owin.compression.
It works well. Thank you!
from owin.compression.
Related Issues (10)
- Integration to OWIN pipeline with Microsoft.Owin.StaticFiles HOT 2
- If the request is being forwarded from one cluster to another. The compression fails probably because it is not checking if response is already compressed HOT 3
- Assuming files are always UTF-8 encoded text HOT 2
- Restrict supported encoding to GZIP
- Missing FSharp.Core dependency HOT 2
- Compression Based on Mime Type of Response HOT 3
- For stream output: Hashcode as eTag cache to avoid compressing and sending resources user already has. HOT 1
- Is there is any reasons why this package not working with Microsoft.Owin 3.1.0 HOT 1
- Build errors due to wrong dependency in Owin.Compression? HOT 14
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from owin.compression.