Giter VIP home page Giter VIP logo

http_stream's Introduction

HTTPStream

Build

HTTPStream is a tiny, tiny package that wraps HTTP requests into a Stream so that you can manage data on the fly, without keeping everything in memory.

Downloading an image:

HTTPStream.get(large_image_url)
|> Stream.into(File.stream!("large_image.png"))
|> Stream.run()

Streaming multiple images into a ZIP archive (using zstream)

[
  Zstream.entry("a.png", HTTPStream.get(a_url))
  Zstream.entry("b.png", HTTPStream.get(b_url))
]
|> Zstream.zip()
|> Stream.into(File.stream!("archive.zip"))
|> Stream.run()

Table of Contents

Installation

First, you need to add http_stream to your list of dependencies on mix.exs:

def deps do
  [
    {:http_stream, "~> 1.0.0"},

    # if using the Mint adapter:
    {:castore, "~> 0.1.7"},
    {:mint, "~> 1.1.0"}

    # if using the HTTPoison adapter:
    {:httpoison, "~> 1.7.0"}
  ]
end

HTTPStream comes with two adapters: Mint and HTTPoison. By default Mint is configured but you need to include it in your dependencies.

To use HTTPoison, set in your config/config.exs:

config :http_stream, adapter: HTTPStream.Adapter.HTTPoison

That's it! For more intricate API details, refer to the documentation.

Development

If you want to setup the project for local development, you can just run the following commands.

git clone [email protected]:subvisual/http_stream.git
cd http_stream
bin/setup

PRs and issues welcome.

Contributing

Feel free to contribute!

If you found a bug, open an issue. You can also open a PR for bugs or new features. Your PRs will be reviewed and subjected to our styleguide and linters.

All contributions must follow the Code of Conduct and Subvisual's guides.

About

HTTPStream is maintained with ❤️ by Subvisual.


Subvisual

http_stream's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

http_stream's Issues

Parsing query string params is a bit odd.

To me it seems odd to pass query params as an enum since they are already in the URL we sent to the lib. My problem is that I have a webserver w/large gzipped assets that only allows me to download with a bad query string.

ie. &Expires=1687269643&Signature=A0rGvq2fJZXfmDDJK-gut5jntqQ9lDFDOMH~WEov8t8z3R174eC0QXDsBR9sNeIRENR2AsWobhscdk8pcHD6uCUeQqRC05Opkr3QYrh-xJyoOm-0ZCpQLIeVMHFAUDyaDJkFx4ERNRU-piLISaKzbJzUl15zqUkaV-T5dcCxRuuLtWssY1tnZS-X3b95HZGqBLbyXiltsEj8s~njxiLPhf26uQajE3IWp-YXu4oS21Ab0onNzZmUTDIhvt3rL-c4MBE6P5lys-5biYgONAJtIVN~JWGUexB2ZdLejk0KCVSlM4R71Ou7UoIAesAX5ZYZT~MhIqzQzEVZgiPMzgnaZg__&Key-Pair-Id=K27TQMT39R1C8A

I just re-implement the library but it looks like this is still a bit raw and depending on the webserver we don't get valid responses so we have to use cURL as a fallback. I've had cases where the file I'm trying to get needs to be resumed in Chrome after failure. I don't expect this lib to handle that case. I'm just saying that in some cases we are doomed.

Example fails to download

I have tried following the examples, e.g.

iex> url = "https://foo.com/large_file.gz"

iex> HTTPStream.get(url)
|> Stream.into(File.stream!("large_file.gz"))
|> Stream.run()

Expected result: the file downloads into the specified target file.

Actual result: Mint adapter:

** (UndefinedFunctionError) function :ssl.cipher_suites/0 is undefined or private, use cipher_suites/2,3 instead
    (ssl 10.5.3) :ssl.cipher_suites()
    (mint 1.1.0) lib/mint/core/transport/ssl.ex:579: Mint.Core.Transport.SSL.default_ciphers/0
    (mint 1.1.0) lib/mint/core/transport/ssl.ex:495: Mint.Core.Transport.SSL.default_ssl_opts/1
    (mint 1.1.0) lib/mint/core/transport/ssl.ex:405: Mint.Core.Transport.SSL.ssl_opts/2
    (mint 1.1.0) lib/mint/core/transport/ssl.ex:318: Mint.Core.Transport.SSL.connect/3
    (mint 1.1.0) lib/mint/negotiate.ex:65: Mint.Negotiate.connect_negotiate/4
    (http_stream 1.0.0) lib/http_stream/adapter/mint.ex:13: HTTPStream.Adapter.Mint.request/1
    (elixir 1.13.0) lib/stream.ex:1517: anonymous fn/5 in Stream.resource/3

Actual result, HTTPoison adapter:

** (ArgumentError) errors were found at the given arguments:

  * 1st argument: the table identifier does not refer to an existing ETS table

    (stdlib 3.16.1) :ets.lookup_element(:hackney_config, :mod_metrics, 2)
    (hackney 1.16.0) /Users/everett/prepos/http_stream/deps/hackney/src/hackney_metrics.erl:27: :hackney_metrics.get_engine/0
    (hackney 1.16.0) /Users/everett/prepos/http_stream/deps/hackney/src/hackney_connect.erl:75: :hackney_connect.create_connection/5
    (hackney 1.16.0) /Users/everett/prepos/http_stream/deps/hackney/src/hackney_connect.erl:44: :hackney_connect.connect/5
    (hackney 1.16.0) /Users/everett/prepos/http_stream/deps/hackney/src/hackney.erl:333: :hackney.request/5
    (httpoison 1.7.0) lib/httpoison/base.ex:796: HTTPoison.Base.request/6
    (elixir 1.13.0) lib/stream.ex:1517: anonymous fn/5 in Stream.resource/3
    (elixir 1.13.0) lib/stream.ex:544: Stream.do_into/4

Other info:

Elixir 1.13.0 (compiled with Erlang/OTP 24)

FYI: hackney is locked at version 1.16.0.

Relax adapter deps

Could the deps on mint and httpoison be relaxed a bit to work with mint 1.4 and httpoison 1.8 without overriding?

Thanks

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.