์ฐ๋ฆฌ๋ Faraday๋ฅผ ์ด๋ ์ ๋ ์ฌ์ฉํ๋ ์๋ฐฑ ๊ฐ์ ํ์ ๊ตฌ์ฑ ์์๊ฐ ์๋ ๊ฝค ํฐ ์ฑ์ ์คํํ๊ณ ์์ต๋๋ค. ์ด๋ฌํ ๊ตฌ์ฑ ์์์ ๋๋ถ๋ถ์ ํ๊ฒฝ ๋ณ์ http_proxy
๋ฑ์ผ๋ก Faraday๋ฅผ ๊ตฌ์ฑํ ๊ฒ์ผ๋ก ์์ํฉ๋๋ค. ๊ทธ๋ค์ ์ฐ๊ฒฐ ์์ฑ์์ ๋ช
์์ ์ธ :proxy
์ค์ ์ ์ ๋ฌํ์ง ์์ต๋๋ค.
๊ทธ๋ฌ๋ ์ผ๋ถ ๊ตฌ์ฑ ์์(์ฝ 100๊ฐ ์ค 2๊ฐ ๋๋ 3๊ฐ)๋ ํ๋ก์ ์์ด ํจ๋ฌ๋ฐ์ด ์ฐ๊ฒฐ์ ์ฌ์ฉํด์ผ ํฉ๋๋ค. ์ฆ, Faraday.ignore_env_proxy = true
๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค. ๊ทธ๋ ์ง ์์ผ๋ฉด ๋๋จธ์ง ~100๊ฐ์ ๊ตฌ์ฑ ์์๊ฐ ์์๋ฉ๋๋ค.
๋ด๊ฐ ๊ฐ๊ณ ์ถ์ ๊ฒ์ ๊ทธ ๋ช ๊ฐ์ง ๊ตฌ์ฑ ์์๊ฐ ํ๊ฒฝ์ด๋ ๋ค๋ฅธ ๋ฐฉ๋ฒ์ผ๋ก ํ๋ก์๋ฅผ ์ฌ์ฉํ์ง ์๋ ํจ๋ฌ๋ฐ์ด ์ฐ๊ฒฐ ๊ฐ์ฒด๋ฅผ ๋ง๋ค ์ ์๋ ๋ฐฉ๋ฒ์ ๋๋ค.
#752์ ์ ์ฌํ๊ฒ ์ด๊ฒ์ ์ฐ๊ฒฐํ ๋ ํ๊ฒฝ์ ํ๋ก์ ์ค์ ์ ์ฌ์ฉํ๋ ํจ๋ฌ๋ฐ์ด ๊ฐ์ฒด๋ฅผ ์์ฑํฉ๋๋ค.
c = Faraday.new('https://www.google.com', proxy: nil)
๋๋ ๋ํ ๋ค์๊ณผ ๊ฐ์ด ๋งค์ฐ ๋๋ํ๊ณ ๋น ํด์๋ฅผ ํ๋ก์ ์ต์ ์ผ๋ก ๋์ ์ ๋ฌํ๋ ค๊ณ ํ์ต๋๋ค.
c = Faraday.new('https://www.google.com', proxy: {})
๊ทธ๋ฌ๋ ๋ค์๊ณผ ํจ๊ป ์ด ์ฐ๊ฒฐ ์ค๋ฅ๋ฅผ ์ฌ์ฉํฉ๋๋ค.
NoMethodError: undefined method `hostname' for nil:NilClass
from vendor/bundle/ruby/2.4.0/gems/faraday-0.15.4/lib/faraday/adapter/net_http.rb:97:in `net_http_connection'
์ด(๋๋ :proxy
์ค์ ์ ํตํด "ํ๋ก์๋ฅผ ์ฌ์ฉํ์ง ๋ง์ญ์์ค"๋ผ๊ณ ๋งํ๋ ๋ค๋ฅธ ๋ฐฉ๋ฒ)๊ฐ ์ง์๋๋ฉด ์ด ๋ฌธ์ ๊ฐ ์์ ํ ํด๊ฒฐ๋ ๊ฒ์ด๋ผ๊ณ ๋ฏฟ์ต๋๋ค.
@asf-stripe ๋๋ ์ด๊ฒ์ ์๋ํ ์ ์ด ์์ง๋ง (์ผ๋ฐ์ ์ผ๋ก ๋ชจ๋ ๋๋ ์ ํ ์์) setter๋ฅผ ์ฌ์ฉํ์ฌ ์ฐ๊ฒฐ์ ์ด๊ธฐํํ ํ ํ๋ก์๋ฅผ nil๋ก ์ค์ ํ ์ ์๋ค๊ณ ์๊ฐํฉ๋๋ค(https://github.com/lostisland/faraday/blob /master/lib/faraday/connection.rb#L397)
c = Faraday.new('https://www.google.com')
c.proxy = nil
์ด๊ฒ์ @manual_proxy
env๋ฅผ true๋ก ์ค์ ํ๊ณ Faraday๊ฐ ํด๋น ํน์ ์ฐ๊ฒฐ์ ๋ํ env๋ฅผ ๋ฌด์ํ๋๋ก ํฉ๋๋ค.
์๋ํ๋์ง ์๋ ค์ฃผ์ธ์ ๐
OMG, ํ์คํ ํด๊ฒฐ ๋ฐฉ๋ฒ์ ๋๋ค. ์ฐ๋ฆฌ๊ฐ ์ง๊ธ๊น์ง ํ ๊ฒ์ ๋ค์๊ณผ ๊ฐ์ ๋ฏธ๋ค์จ์ด์์ต๋๋ค(Octokit ์ฌ์ฉ์ ์ํด):
# A Faraday middleware that throws out any configured proxy away
# from the request environment, to make connections to GHE work
# (those must not be proxied).
class ProxyDroppingMiddleware < Faraday::Middleware
def call(request_env)
request_env[:request][:proxy] = nil
@app.call(request_env)
end
end
๊ทธ๋ฆฌ๊ณ ์ฅํ ํท์ ์ด๊ธฐํํ ๋๊ฐ ๋๋ฉด:
stack = Faraday::RackBuilder.new do |builder|
builder.use ProxyDroppingMiddleware
# What follows is the default octokit middleware:
builder.use Faraday::Request::Retry, exceptions: [Octokit::ServerError]
builder.use Octokit::Middleware::FollowRedirects
builder.use Octokit::Response::RaiseError
builder.use Octokit::Response::FeedParser
builder.adapter Faraday.default_adapter
end
options[:middleware] = stack
๋ด๊ฐ ๋งํ ์ ์๋ ๋ฐ์ ๋ฐ๋ฅด๋ฉด ๋ฏธ๋ค์จ์ด ํด๊ฒฐ ๋ฐฉ๋ฒ์ octokit์์ ๋ ์ ์๋ํฉ๋๋ค. ๊ทธ๋ ์ง ์์ผ๋ฉด ์์ฑ ํ Faraday ๊ฐ์ฒด๋ฅผ ํจ์นํ๊ธฐ ์ํด octokit ๋ํผ๋ฅผ ๋ง๋ค์ด์ผ ํฉ๋๋ค.
์ ์, ์ ์๋ฃจ์
์ ์ค์ ์ฐ๊ฒฐ์ ๋ํ ์ก์ธ์ค ๊ถํ์ด ์๋ ๊ฒฝ์ฐ์๋ง ์๋ํฉ๋๋ค(๋ํผ ์ฌ์ฉ ๋๋ instance_variable_get
๊ฐ์ ๊ฒ์ ์ฌ์ฉ). ๋๋ ๋น์ ์ด ์ฒซ ๋ฒ์งธ ๊ฒ์๋ฌผ์์ ์ธ๊ธํ ์๋๋ฅผ ๋ณด๊ณ ๊ทธ ๊ฒฝ์ฐ๋ผ๊ณ ์๊ฐํ์ต๋๋ค.
๋ด ์ ์์ด ํจ๊ณผ๊ฐ ์๊ณ ๋ค๋ฅธ ๊ฒฝ์ฐ์ ๋ํ ์ฌ์ฉ์ ์ ์ ๋ฏธ๋ค์จ์ด๊ฐ ์๋ค๋ ์์์ ๋ฃ๊ณ ๊ธฐ์ฉ๋๋ค.
์ด ๋ฌธ์ ๋ฅผ ์ข
๋ฃํ์ง๋ง ์ฌ์ ํ ๋์์ด ํ์ํ๋ฉด ์ฐ๋ฝํด ์ฃผ์ธ์ ๐
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
OMG, ํ์คํ ํด๊ฒฐ ๋ฐฉ๋ฒ์ ๋๋ค. ์ฐ๋ฆฌ๊ฐ ์ง๊ธ๊น์ง ํ ๊ฒ์ ๋ค์๊ณผ ๊ฐ์ ๋ฏธ๋ค์จ์ด์์ต๋๋ค(Octokit ์ฌ์ฉ์ ์ํด):
๊ทธ๋ฆฌ๊ณ ์ฅํ ํท์ ์ด๊ธฐํํ ๋๊ฐ ๋๋ฉด:
๋ด๊ฐ ๋งํ ์ ์๋ ๋ฐ์ ๋ฐ๋ฅด๋ฉด ๋ฏธ๋ค์จ์ด ํด๊ฒฐ ๋ฐฉ๋ฒ์ octokit์์ ๋ ์ ์๋ํฉ๋๋ค. ๊ทธ๋ ์ง ์์ผ๋ฉด ์์ฑ ํ Faraday ๊ฐ์ฒด๋ฅผ ํจ์นํ๊ธฐ ์ํด octokit ๋ํผ๋ฅผ ๋ง๋ค์ด์ผ ํฉ๋๋ค.