From cf9d7c72491ceb4a9da73985349ca7a8d8b1e280 Mon Sep 17 00:00:00 2001 From: Dov Frankel Date: Mon, 29 Jul 2019 17:47:50 -0400 Subject: [PATCH 1/5] Added user_agent argument to http methods so it can be overridden by a caller, so the social media validator can specify something different (Issue CocoaPods/CocoaPods#9049) --- lib/cocoapods-core/http.rb | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/cocoapods-core/http.rb b/lib/cocoapods-core/http.rb index da5c2a8b4..cd379c7a0 100644 --- a/lib/cocoapods-core/http.rb +++ b/lib/cocoapods-core/http.rb @@ -8,11 +8,11 @@ module HTTP # # @return [string] # - def self.get_actual_url(url) + def self.get_actual_url(url, user_agent=nil) redirects = 0 loop do - response = perform_head_request(url) + response = perform_head_request(url, user_agent) if [301, 302, 303, 307, 308].include? response.status_code location = response.headers['location'].first @@ -38,12 +38,12 @@ def self.get_actual_url(url) # # @return [REST::response] # - def self.validate_url(url) + def self.validate_url(url, user_agent=nil) return nil unless url =~ /^#{URI.regexp}$/ begin - url = get_actual_url(url) - resp = perform_head_request(url) + url = get_actual_url(url, user_agent) + resp = perform_head_request(url, user_agent) rescue SocketError, URI::InvalidURIError, REST::Error, REST::Error::Connection resp = nil end @@ -59,17 +59,19 @@ def self.validate_url(url) # # @return [REST::response] # - def self.perform_head_request(url) + def self.perform_head_request(url, user_agent) require 'rest' - resp = ::REST.head(url, 'User-Agent' => USER_AGENT) + user_agent ||= USER_AGENT + + resp = ::REST.head(url, 'User-Agent' => user_agent) if resp.status_code >= 400 - resp = ::REST.get(url, 'User-Agent' => USER_AGENT, + resp = ::REST.get(url, 'User-Agent' => user_agent, 'Range' => 'bytes=0-0') if resp.status_code >= 400 - resp = ::REST.get(url, 'User-Agent' => USER_AGENT) + resp = ::REST.get(url, 'User-Agent' => user_agent) end end From 372e7df9baaa90f5e2785b183e99d64395c85623 Mon Sep 17 00:00:00 2001 From: Dov Frankel Date: Mon, 29 Jul 2019 18:07:09 -0400 Subject: [PATCH 2/5] Updated changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ee626bc9..389f03dec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,10 @@ [Eric Amorde](https://github.com/amorde) [CocoaPods/CocoaPods#8785](https://github.com/CocoaPods/CocoaPods/issues/8785) +* Pass a non-browser user agent for social media validation + [Dov Frankel](https://github.com/abbeycode) + [#571](https://github.com/CocoaPods/Core/pull/571) + [CocoaPods#9049](https://github.com/CocoaPods/CocoaPods/issues/9049) ## 1.7.5 (2019-07-19) From 8d5efa2cc313e8742a760ff388709b7707223b4e Mon Sep 17 00:00:00 2001 From: Dov Frankel Date: Mon, 29 Jul 2019 22:10:08 -0400 Subject: [PATCH 3/5] Added spaces to changelog entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 389f03dec..d96b9080e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,7 +45,7 @@ [Eric Amorde](https://github.com/amorde) [CocoaPods/CocoaPods#8785](https://github.com/CocoaPods/CocoaPods/issues/8785) -* Pass a non-browser user agent for social media validation +* Pass a non-browser user agent for social media validation [Dov Frankel](https://github.com/abbeycode) [#571](https://github.com/CocoaPods/Core/pull/571) [CocoaPods#9049](https://github.com/CocoaPods/CocoaPods/issues/9049) From ad4743d45d42072d756c6af5506717f7405af771 Mon Sep 17 00:00:00 2001 From: Dov Frankel Date: Mon, 29 Jul 2019 22:12:51 -0400 Subject: [PATCH 4/5] Fixed style violations --- lib/cocoapods-core/http.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/cocoapods-core/http.rb b/lib/cocoapods-core/http.rb index cd379c7a0..bf5f0b98b 100644 --- a/lib/cocoapods-core/http.rb +++ b/lib/cocoapods-core/http.rb @@ -8,7 +8,7 @@ module HTTP # # @return [string] # - def self.get_actual_url(url, user_agent=nil) + def self.get_actual_url(url, user_agent = nil) redirects = 0 loop do @@ -38,7 +38,7 @@ def self.get_actual_url(url, user_agent=nil) # # @return [REST::response] # - def self.validate_url(url, user_agent=nil) + def self.validate_url(url, user_agent = nil) return nil unless url =~ /^#{URI.regexp}$/ begin From 3cefc3a22b2ecfffe7aa43507cb30cb2eb8a7761 Mon Sep 17 00:00:00 2001 From: Dov Frankel Date: Mon, 29 Jul 2019 22:22:44 -0400 Subject: [PATCH 5/5] Added reference to related CocoaPods project PR --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d96b9080e..7a4593989 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,7 @@ * Pass a non-browser user agent for social media validation [Dov Frankel](https://github.com/abbeycode) [#571](https://github.com/CocoaPods/Core/pull/571) + [CocoaPods#9053](https://github.com/CocoaPods/Cocoapods/pull/9053) [CocoaPods#9049](https://github.com/CocoaPods/CocoaPods/issues/9049) ## 1.7.5 (2019-07-19)