forked from OpenNeo/impress
Merge pull request #4 from openneo:proxy-for-https-images
Sigh, fix HTTPS for images AGAIN with a proxy now
This commit is contained in:
commit
4446209ec4
1 changed files with 10 additions and 13 deletions
|
@ -11,7 +11,7 @@ class SwfAsset < ActiveRecord::Base
|
||||||
'Cache-Control' => 'max-age=315360000',
|
'Cache-Control' => 'max-age=315360000',
|
||||||
'Content-Type' => 'image/png'
|
'Content-Type' => 'image/png'
|
||||||
}
|
}
|
||||||
NEOPETS_ASSET_SERVER = 'http://images.neopets.com'
|
NEOPETS_IMAGES_URL_ORIGIN = ENV['NEOPETS_IMAGES_URL_ORIGIN'] || 'http://images.neopets.com'
|
||||||
|
|
||||||
set_inheritance_column 'inheritance_type'
|
set_inheritance_column 'inheritance_type'
|
||||||
|
|
||||||
|
@ -248,7 +248,7 @@ class SwfAsset < ActiveRecord::Base
|
||||||
|
|
||||||
def mall_data=(data)
|
def mall_data=(data)
|
||||||
self.zone_id = data['zone'].to_i
|
self.zone_id = data['zone'].to_i
|
||||||
self.url = "#{NEOPETS_ASSET_SERVER}/#{data['url']}"
|
self.url = "#{NEOPETS_IMAGES_URL_ORIGIN}/#{data['url']}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.from_wardrobe_link_params(ids)
|
def self.from_wardrobe_link_params(ids)
|
||||||
|
@ -260,17 +260,14 @@ class SwfAsset < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
before_create do
|
before_create do
|
||||||
uri = URI.parse url
|
# HACK: images.neopets.com no longer accepts requests over `http://`, and
|
||||||
# NOTE: Our old Ruby can't do the HTTPS the images.neopets.com server
|
# our dependencies don't support the version of HTTPS they want. So,
|
||||||
# wants. We turn it off instead! Sigh. Should be fine since we
|
# we replace images.neopets.com with the NEOPETS_IMAGES_URL_ORIGIN
|
||||||
# don't anticipate like, an MITM attack against our VPS.
|
# specified in the secret `.env` file. (At time of writing, that's
|
||||||
#
|
# our proxy: `http://images.neopets-asset-proxy.openneo.net`.)
|
||||||
# Also, we re-parse after setting the scheme, to change the
|
modified_url = url.sub(/^https?:\/\/images.neopets.com/, NEOPETS_IMAGES_URL_ORIGIN)
|
||||||
# class to URI:HTTP. This especially matters for URIs that
|
|
||||||
# were given to us as "//images.neopets.com", because they
|
uri = URI.parse(modified_url)
|
||||||
# don't have a `request_uri` method.
|
|
||||||
uri.scheme = 'http'
|
|
||||||
uri = URI.parse(uri.to_s)
|
|
||||||
begin
|
begin
|
||||||
http = Net::HTTP.new(uri.host, uri.port)
|
http = Net::HTTP.new(uri.host, uri.port)
|
||||||
response = http.get(uri.request_uri)
|
response = http.get(uri.request_uri)
|
||||||
|
|
Loading…
Reference in a new issue