Giter Site home page Giter Site logo

Comments (14)

relentless avatar relentless commented on August 20, 2024

Hi had, what would you want the body to be? Raw bytes? Fields? (Which do get encoded as a string, bit we could certainly add functions to make that easier.)

from http.fs.

haf avatar haf commented on August 20, 2024

Not always string, sometimes raw bytes like here https://github.com/SuaveIO/suave/blob/master/src/Suave/Web.fs#L216

from http.fs.

relentless avatar relentless commented on August 20, 2024

Sorry, haf not 'had' - autocorrect user error!

Should be doable, I'll try and have a look this weekend.

from http.fs.

relentless avatar relentless commented on August 20, 2024

OK, I've put this on github, there's now a withBodyBytes function.

The way I've implemented it is a (slightly) breaking change to the API - do you think you'd be able to have a look and see if it meets your needs, before I make a NuGet from it?

from http.fs.

haf avatar haf commented on August 20, 2024

Yes, sure - but perhaps you could see if the API matches; the change I'd need is to make these lines: https://github.com/SuaveIO/suave/blob/master/src/Suave.Testing/Testing.fs#L123-L190 work with Http.fs - and as a side-effect you would test almost the full implementation of Http.fs.

from http.fs.

relentless avatar relentless commented on August 20, 2024

I'll give it a look if I get the chance - having problems getting the build system working on my work PC. One thing is the timeout, which there's currently no way to set with Http.fs, but would be easy to add.

from http.fs.

Muhomorik avatar Muhomorik commented on August 20, 2024

Hi,
Also, would be nice with a key-value list. Body if often used to make Post requests on forms with correct Content-Type.
Mostly, it is application/x-www-form-urlencoded, but there may be other
text/plain
multipart/form-data
application/json

Something like:

    let request =  
        createRequest Post "http://somesite.com"  
        |> withBodyItem {name="firstName"; value="John"} 
        |> withBodyItem {name="lastName"; value="Doe"}
        |> withHeader (ContentType "application/x-www-form-urlencoded")

from http.fs.

relentless avatar relentless commented on August 20, 2024

Hi @Muhomorik, yes that would be pretty easy to add. I'm not sure about the name, but I can't think of a better one and it matches 'withQueryStringItem'. I'd be tempted to default the content type to x-www-form-urlencoded, but that would be confusing if someone had set the content type earlier, and there might be situations where people don't want to set it. Perhaps best just let the user set it as per your example.

If you want to have a crack at it and send me a PR go for it, otherwise I'll add it when I can, won't be for at least a week or so though.

from http.fs.

Muhomorik avatar Muhomorik commented on August 20, 2024

@relentless Not setting content type sends request anyway, so maybe a good idea to leave to the user.
I am afraid I am quite new to F# programming and not right there to send PR yet.

from http.fs.

haf avatar haf commented on August 20, 2024

Would be great to also have an interface for adding files to the request, beyond just having a body full of bytes. Otherwise I'd have to write the file encoding myself, as well as the boundary in the form.

from http.fs.

haf avatar haf commented on August 20, 2024

Like so http://code.activestate.com/recipes/578668-encode-multipart-form-data-for-uploading-files-via/

from http.fs.

haf avatar haf commented on August 20, 2024

I've browsed the code a bit, and I'm not sure it's a good idea to flush the body when you use setBody and setBodyBytes.

Would be better to have a ByteBody and a StreamBody as possible values to set to your Request object, so that I can re-use the request object and also be very specific about when I want the data to be 'used'/stream disposed.

from http.fs.

haf avatar haf commented on August 20, 2024

Something like this

  let body =
    // http://ftp.isi.edu/in-notes/rfc2046.txt
    String.concat "\r\n" [
      yield "--" + boundary
      yield sprintf "Content-Disposition: form-data; name=\"file\"; filename=\"%s\""
                    (escapeQuotes file.name)
      yield sprintf "Content-Type: %s" (file.guessMime ())
      use ms = new MemoryStream()
      stream.CopyTo ms
      yield ""
      yield Convert.ToBase64String (ms.ToArray())
      yield "--" + boundary + "--"
    ]

from http.fs.

haf avatar haf commented on August 20, 2024

Closing in favour of #65 and related child-issues.

from http.fs.

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.