Skip to content
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

Add DownloadStrategy with custom :headers support #1944

Merged
merged 1 commit into from Dec 15, 2013
Merged

Add DownloadStrategy with custom :headers support #1944

merged 1 commit into from Dec 15, 2013

Conversation

jonahoffline
Copy link
Contributor

This adds support for overriding the default UserAgent that curl adds by default and also accepts a :cookies hash.
@nanoxd - #1175 called for a DownloadStrategy with UserAgent support to avoid problems related to 403's / Spam in Detection like #984, but after seeing so many brackets pull-requests that fail and a few issues related to being limited by the original CurlDownloadStrategy; I think it would be good to incorporate a simple headers option that can be extended as needed.

A few examples:

  headers :user_agent => 'Netscape/1.0'
  headers :user_agent => 'Lynx/1.7', :cookies => { :cookey => "r00t", :cookey2 => "k4w411" }
  headers :cookies => { :cookey => "r00t" }

For a simple UserAgent, you can use the standalone :fake_user_agent that impersonates Chrome.

  fake_user_agent

The :cookies option is based on #958
which has been sitting for 2 months with no answer from the author so I went ahead and did some small changes and used it.

References #1175

@phinze
Copy link
Contributor

phinze commented Dec 5, 2013

Wow this is great work! I've been meaning to do this for quite some time.

@nanoxd
Copy link
Contributor

nanoxd commented Dec 5, 2013

No sabia que usabas el proyecto. Thanks for the contribution, let me look over this and do some testing.

end
downloader = CurlDownloadStrategy.new(cask.title, resource)
end
downloader = Cask::DownloadStrategy.new(cask.title, resource, cask.headers)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we own the DownloadStrategy interface, can can make it just take (cask, resource) and then have the DownloadStrategy retrieve the data it needs directly from the Cask?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right! I can fix it :)

@jonahoffline
Copy link
Contributor Author

👍 Just found about it Today while looking to install vagrant (thanks @phinze).

Queria contribuir algo :)

@@ -27,6 +36,14 @@ def url(url=nil)
@url ||= Cask::UnderscoreSupportingURI.parse(url)
end

def headers(headers=nil)
@headers ||= OpenStruct.new(headers)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anything gained by the OpenStruct here other than dot notation? It seems like the marshall_dump stuff is extra work that would fall away if we just switched to a straight hash here.

If interaction with a hash gets hairy, I'd recommend spinning up a new Cask::Headers object to encapsulate the data.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the dot notation, there's actually nothing else. I like the idea of having Cask::Headers I had thought about this but was reluctant to keep adding classes but for this I think it makes sense. I have some free time Tonight so I'll get to this and the previous change suggested ASAP.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool - no rush of course - this is FOSS. 🐵

Feel free to hop in #homebrew-cask on freenode if you have any other questions.

@jonahoffline
Copy link
Contributor Author

btw, with these changes brackets finally install with no problems. No more CAPTCHA 🎆

accepts a :user_agent argument and/or multiple :cookies
  headers :user_agent => 'Netscape/1.0', :cookies => { :cookey => "r00t" }

Also adds a standalone :fake_user_agent for a default UserAgent (Chrome)
  fake_user_agent
References #1175, #958
phinze added a commit that referenced this pull request Dec 15, 2013
Add DownloadStrategy with custom :headers support
@phinze phinze merged commit 06be4b0 into Homebrew:master Dec 15, 2013
@phinze
Copy link
Contributor

phinze commented Dec 15, 2013

Landed with some refactoring. Working on a few docs now.

@jonahoffline jonahoffline deleted the add_headers_download_strategy branch December 15, 2013 20:36
@Homebrew Homebrew locked and limited conversation to collaborators May 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants