Giter VIP home page Giter VIP logo

Comments (4)

abonander avatar abonander commented on June 9, 2024

How about an adapter that implements Read? With multipart::client::lazy::Multipart you can build your multipart body then call .prepare() which returns a type that implements Read, that you should then be able to return as your response body, or copy out to your response, depending on what HTTP framework you're using.

from multipart.

SirVer avatar SirVer commented on June 9, 2024

That might work, but it still sounds complicated. Could you explain why tying the construction of the body of the HTML request is so strongly tied to a Request or a Client? Is that because of streaming?

from multipart.

abonander avatar abonander commented on June 9, 2024

It's primarily to ensure that the right header is supplied with the request. The multipart boundary that separates each field in the body has to be supplied in the Content-Type header of the request, and each HTTP framework does headers slightly differently. This approach has better ergonomics for the common case where you're constructing the multipart body in the process of submitting a request. Otherwise it would be easy to forget to supply the boundary with the request and would cause difficult to debug errors on the server side.

I've done a different approach in src\local_test.rs where I have a mock implementation of HttpRequest that simply writes the request to a Vec and stores the boundary. I could extract this to the library proper but I didn't see the utility in it outside of testing.

from multipart.

SirVer avatar SirVer commented on June 9, 2024

Thanks for explaining everything!

I took a different approach for my problem now, so this is not required for me anymore and I think my use case was rather esoteric. I would suggest you do not pull the code out until the next one with a similar problem comes around. Closing the issue for now.

from multipart.

Related Issues (20)

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.