Skip to content

Commit 055ebd3

Browse files
authored
Fix net http request on ruby 2.7 (#130)
* Fix Net::HTTP Get request under Ruby 2.7 * Add section in the Readme about outdated and audit
1 parent c69cefd commit 055ebd3

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,12 @@ In Firefox. when opening the browser console, the asm.js module lexer build will
299299

300300
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.
301301

302+
## Checking for outdated or vulnerable packages
303+
304+
Importmap for Rails provides two commands to check your pinned packages:
305+
- `./bin/importmap outdated` checks the NPM registry for new versions
306+
- `./bin/importmap audit` checks the NPM registry for known security issues
307+
302308
## License
303309

304310
Importmap for Rails is released under the [MIT License](https://opensource.org/licenses/MIT).

lib/importmap/npm.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,14 @@ def get_package(package)
7171
end
7272

7373
def get_json(uri)
74-
Net::HTTP.get(uri, "Content-Type" => "application/json")
74+
request = Net::HTTP::Get.new(uri)
75+
request["Content-Type"] = "application/json"
76+
77+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http|
78+
http.request(request)
79+
}
80+
81+
response.body
7582
rescue => error
7683
raise HTTPError, "Unexpected transport error (#{error.class}: #{error.message})"
7784
end

test/npm_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Importmap::NpmTest < ActiveSupport::TestCase
3232
end
3333

3434
test "failed outdated packages request with mock" do
35-
Net::HTTP.stub(:get, proc { raise "Unexpected Error" }) do
35+
Net::HTTP.stub(:start, proc { raise "Unexpected Error" }) do
3636
assert_raises(Importmap::Npm::HTTPError) do
3737
@npm.outdated_packages
3838
end

0 commit comments

Comments
 (0)