-
Notifications
You must be signed in to change notification settings - Fork 16
1.5.0: arm64 + dynamic CloudFront source URL (LOC-6563) #39
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,21 @@ | ||
| require File.expand_path('../lib/browserstack/version', __FILE__) | ||
|
|
||
| Gem::Specification.new do |s| | ||
| s.name = 'browserstack-local' | ||
| s.version = '1.4.3' | ||
| s.date = '2023-08-24' | ||
| s.version = BrowserStack::VERSION | ||
| s.date = '2026-06-01' | ||
| s.summary = "BrowserStack Local" | ||
| s.description = "Ruby bindings for BrowserStack Local" | ||
| s.authors = ["BrowserStack"] | ||
| s.email = 'support@browserstack.com' | ||
| s.files = ["lib/browserstack/local.rb", "lib/browserstack/localbinary.rb", "lib/browserstack/localexception.rb"] | ||
| s.files = [ | ||
| "lib/browserstack/local.rb", | ||
| "lib/browserstack/localbinary.rb", | ||
| "lib/browserstack/localexception.rb", | ||
| "lib/browserstack/fetch_download_source_url.rb", | ||
| "lib/browserstack/version.rb" | ||
| ] | ||
| s.homepage = | ||
| 'http://rubygems.org/gems/browserstack-local' | ||
| s.license = 'MIT' | ||
| end | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| require 'net/http' | ||
| require 'net/https' | ||
| require 'json' | ||
| require 'openssl' | ||
| require 'browserstack/localexception' | ||
|
|
||
| module BrowserStack | ||
| module FetchDownloadSourceUrl | ||
| BS_HOST = 'local.browserstack.com'.freeze | ||
| ENDPOINT_PATH = '/binary/api/v1/endpoint'.freeze | ||
|
|
||
| def self.call(auth_token:, user_agent:, fallback: false, error_message: nil, | ||
| proxy_host: nil, proxy_port: nil) | ||
| uri = URI::HTTPS.build(host: BS_HOST, path: ENDPOINT_PATH) | ||
|
|
||
| body = { 'auth_token' => auth_token } | ||
| body['error_message'] = error_message if fallback && error_message | ||
|
|
||
| http_class = if proxy_host && proxy_port | ||
| Net::HTTP::Proxy(proxy_host, proxy_port.to_i) | ||
| else | ||
| Net::HTTP | ||
| end | ||
|
|
||
| http = http_class.new(uri.host, uri.port) | ||
| http.use_ssl = true | ||
| http.verify_mode = OpenSSL::SSL::VERIFY_PEER | ||
| http.open_timeout = 10 | ||
| http.read_timeout = 15 | ||
|
|
||
| req = Net::HTTP::Post.new(uri.request_uri) | ||
| req['Content-Type'] = 'application/json' | ||
| req['User-Agent'] = user_agent | ||
| req['X-Local-Fallback-Cloudflare'] = 'true' if fallback | ||
| req.body = JSON.dump(body) | ||
|
|
||
| res = http.request(req) | ||
|
|
||
| begin | ||
| parsed = JSON.parse(res.body.to_s) | ||
| rescue JSON::ParserError => e | ||
| raise BrowserStack::LocalException.new( | ||
| "Failed to parse binary endpoint API response (HTTP #{res.code}): #{e.message}" | ||
| ) | ||
| end | ||
|
|
||
| if parsed.is_a?(Hash) && parsed['error'] | ||
| raise BrowserStack::LocalException.new( | ||
| "Binary endpoint API returned error: #{parsed['error']}" | ||
| ) | ||
| end | ||
|
|
||
| endpoint = parsed.is_a?(Hash) ? parsed.dig('data', 'endpoint') : nil | ||
| if endpoint.nil? || endpoint.to_s.empty? | ||
| raise BrowserStack::LocalException.new( | ||
| "Binary endpoint API returned no endpoint (HTTP #{res.code})" | ||
| ) | ||
| end | ||
|
|
||
| endpoint | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,7 +64,11 @@ def start(options = {}) | |
| end | ||
|
|
||
| @binary_path = if @binary_path.nil? | ||
| BrowserStack::LocalBinary.new.binary_path | ||
| BrowserStack::LocalBinary.new( | ||
| auth_token: @key, | ||
| proxy_host: @proxy_host, | ||
| proxy_port: @proxy_port | ||
| ).binary_path | ||
|
Comment on lines
+69
to
+71
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is the reason for adding proxy_host & proxy_port?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Used node binding as a reference, it had proxy support that we never propagated to other bindings, used this PR as an opportunity to do so. |
||
| else | ||
| @binary_path | ||
| end | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| module BrowserStack | ||
| VERSION = '1.5.0'.freeze | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we keep this line in begin, rescue block?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is rescued downstream -- see
FetchDownloadSourceUrl