Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

README corrections #159

Open
rm2 opened this issue Feb 13, 2019 · 0 comments
Open

README corrections #159

rm2 opened this issue Feb 13, 2019 · 0 comments

Comments

@rm2
Copy link

rm2 commented Feb 13, 2019

The README currently states:

2 - The Http response (or just the response code/body) is retrieved using one of the following:

job {
  use! response = getResponse request // disposed at the end of async, don't
                                      // fetch outside async body
  // the above doesn't download the response, so you'll have to do that:
  let! bodyStr = Response.readBodyAsString response
  // OR:
  //let! bodyBs = Response.readBodyAsBytes

  // remember HttpFs doesn't buffer the stream (how would we know if we're
  // downloading 3GiB?), so once you use one of the above methods, you can't do it
  // again, but have to buffer/stash it yourself somewhere.
  return bodyStr
}

IMO it should really say:

2 - The Http response (or just the response code/body) is retrieved using one of the following:

job {
use! response = getResponse request // disposed at the end of Hopac job, don't
// fetch outside Hopac job body
// while the above does download the full response, it doesn't give you access to the body content. You'll have to do this:
let! bodyStr = Response.readBodyAsString response
// OR:
//let! bodyBs = Response.readBodyAsBytes

// remember HttpFs doesn't buffer the stream (how would we know if we're
// downloading 3GiB?), so once you use one of the above methods, you can't do it
// again, but have to buffer/stash it yourself somewhere.
return bodyStr
}

as demonstrated by issue #158, wherein I got the full response even though I didn't think I was asking for it. And perhaps even say (the more examples of using Hopac with HttpFs in various situations the better), to be explicit:

If for some reason, you only want to get the headers, instead do:

let statusCode, contentType, headers =
  Hopac.Hopac.job {
    use! response = HttpFs.Client.getEventSourceResponse request
    let statusCode = response.statusCode
    let contentType = response.headers.[HttpFs.Client.ResponseHeader.ContentTypeResponse]
   return statusCode, contentType, response.headers
  } |> Hopac.Hopac.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant