Skip to content

Fix net http request on ruby 2.7 #130

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

Merged
merged 2 commits into from
Jun 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,12 @@ In Firefox. when opening the browser console, the asm.js module lexer build will

Under certain circumstances, like running system tests using chromedriver under CI (which may be resource constrained and trigger errors in certain cases), you may want to explicitly turn off including the shim. You can do this by calling the bulk tag helper with `javascript_importmap_tags("application", shim: false)`. Thus you can pass in something like `shim: !ENV["CI"]`. If you want, and are sure you're not doing any full-page caching, you can also connect this directive to a user agent check (using a gem like `useragent`) to check whether the browser is chrome/edge 89+. But you really shouldn't have to, as the shim is designed to gracefully work with natively compatible drivers.

## Checking for outdated or vulnerable packages

Importmap for Rails provides two commands to check your pinned packages:
- `./bin/importmap outdated` checks the NPM registry for new versions
- `./bin/importmap audit` checks the NPM registry for known security issues

## License

Importmap for Rails is released under the [MIT License](https://opensource.org/licenses/MIT).
9 changes: 8 additions & 1 deletion lib/importmap/npm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,14 @@ def get_package(package)
end

def get_json(uri)
Net::HTTP.get(uri, "Content-Type" => "application/json")
request = Net::HTTP::Get.new(uri)
request["Content-Type"] = "application/json"

response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http|
http.request(request)
}

response.body
rescue => error
raise HTTPError, "Unexpected transport error (#{error.class}: #{error.message})"
end
Expand Down
2 changes: 1 addition & 1 deletion test/npm_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Importmap::NpmTest < ActiveSupport::TestCase
end

test "failed outdated packages request with mock" do
Net::HTTP.stub(:get, proc { raise "Unexpected Error" }) do
Net::HTTP.stub(:start, proc { raise "Unexpected Error" }) do
assert_raises(Importmap::Npm::HTTPError) do
@npm.outdated_packages
end
Expand Down