Giter VIP home page Giter VIP logo

Comments (12)

Thorium avatar Thorium commented on May 31, 2024

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.

Thorium avatar Thorium commented on May 31, 2024

Hmm... Was the context.Response.Body empty at the time of calculation?

from owin.compression.

Moachi avatar Moachi commented on May 31, 2024

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.

Thorium avatar Thorium commented on May 31, 2024

I have not experienced this. So maybe the order of middleware-registration is significant.

from owin.compression.

Moachi avatar Moachi commented on May 31, 2024

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.

Thorium avatar Thorium commented on May 31, 2024

Can you send a PR?

from owin.compression.

Thorium avatar Thorium commented on May 31, 2024

Is this only for streams?

from owin.compression.

Moachi avatar Moachi commented on May 31, 2024

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.

Thorium avatar Thorium commented on May 31, 2024

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.

Moachi avatar Moachi commented on May 31, 2024

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.

Thorium avatar Thorium commented on May 31, 2024

This is now added to NuGet version 1.1.18. Hopefully helps.

from owin.compression.

Moachi avatar Moachi commented on May 31, 2024

It works well. Thank you!

from owin.compression.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.