I can't seem to get Faraday.get
to accept the user:pass@host syntax from a url and respect it. URL์์ user:pass@host ๊ตฌ๋ฌธ์ ์๋ฝํ๊ณ ์กด์คํ๋๋ก Faraday.get
๋ฅผ ์ป์ ์ ์๋ ๊ฒ ๊ฐ์ต๋๋ค.
Reproducing with Faraday 0.9.0 ํจ๋ฌ๋ฐ์ด 0.9.0์ผ๋ก ์ฌํ
Faraday.get("http://foo:bar<strong i="9">@localhost</strong>:3333/test")
The "server" ์๋ฒ"
% nc -l localhost 3333
GET /test HTTP/1.1
User-Agent: Faraday v0.9.0
Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Accept: */*
Connection: close
Host: localhost:3333
I expected an Authentication header, or perhaps an error that auth wasn't supported. ์ธ์ฆ ํค๋๋ฅผ ์์ํ๊ฑฐ๋ ์ธ์ฆ์ด ์ง์๋์ง ์๋ ์ค๋ฅ์ผ ์ ์์ต๋๋ค.
I couldn't find docs on the Faraday.get
method on rubydoc.info for the Faraday module: http://www.rubydoc.info/gems/faraday/Faraday - so I'm not sure what I'm doing wrong. ํจ๋ฌ๋ฐ์ด ๋ชจ๋์ ๋ํ rubydoc.info์ Faraday.get
๋ฉ์๋์ ๋ํ ๋ฌธ์๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค. http://www.rubydoc.info/gems/faraday/Faraday - ๊ทธ๋์ ๋ด๊ฐ ๋ฌด์์ธ์ง ์ ๋ชจ๋ฅด๊ฒ ์ต๋๋ค. ์๋ชปํ๊ณ ์์ต๋๋ค.
If you point me in the write direction, I am happy to write documentation for this method. ์ฐ๊ธฐ ๋ฐฉํฅ์ ์๋ ค์ฃผ์๋ฉด ์ด ๋ฐฉ๋ฒ์ ๋ํ ๋ฌธ์๋ฅผ ์์ฑํ๊ฒ ์ต๋๋ค.
enThere are several ways you can set authentication headers with Faraday. Faraday๋ก ์ธ์ฆ ํค๋๋ฅผ ์ค์ ํ ์ ์๋ ๋ฐฉ๋ฒ์๋ ์ฌ๋ฌ ๊ฐ์ง๊ฐ ์์ต๋๋ค. One way is to initialize a Faraday::Connection
instance and use the basic_auth
helper method: ํ ๊ฐ์ง ๋ฐฉ๋ฒ์ Faraday::Connection
basic_auth
๋์ฐ๋ฏธ ๋ฉ์๋๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์
๋๋ค.
conn = Faraday.new(url: 'http://example.com') # create a new Connection with base URL
conn.basic_auth('user', 'pass') # set the Authentication header
conn.get('/foo') # GET http://example.com/foo
You could also use middleware: ๋ฏธ๋ค์จ์ด๋ฅผ ์ฌ์ฉํ ์๋ ์์ต๋๋ค.
conn = Faraday.new(url: 'http://example.com') do |builder|
builder.use Faraday::Request::Retry
builder.use Faraday::Request::BasicAuthentication, 'user', 'pass'
builder.use Faraday::Response::Logger
builder.use Faraday::Adapter::NetHttp
end
conn.get('/foo')
or: ๋๋:
Faraday.new(url: 'http://example.com') do |builder|
builder.request :retry
builder.request :basic_authentication, 'user', 'pass'
builder.response :logger
builder.adapter :net_http
end
conn.get('/foo')
Intridea has a nice blog post on basic Faraday usage that's a few years old but still relevant. Intridea์๋ ๋ช ๋ ์ ์ด์ง๋ง ์ฌ์ ํ ๊ด๋ จ์ฑ์ด ์๋ ๊ธฐ๋ณธ์ ์ธ ํจ๋ฌ๋ฐ์ด ์ฌ์ฉ๋ฒ ์ ๋ํ ๋ฉ์ง ๋ธ๋ก๊ทธ ๊ฒ์๋ฌผ์ด ์์ต๋๋ค.
Hope it helps some, ์กฐ๊ธ์ด๋๋ง ๋์์ด ๋๊ธธ ๋ฐ๋ผ๋ฉฐ,
OI ์ค์ด
Thanks @OI for the helpful examples. ์ ์ฉํ ์์ ๋ฅผ ์ ๊ณตํ @OI์๊ฒ ๊ฐ์ฌ๋๋ฆฝ๋๋ค.
@jordansissel For now, please use this form: @jordansissel ์ง๊ธ์ ๋ค์ ์์์ ์ฌ์ฉํ์ธ์.
conn = Faraday.new('http://example.com')
conn.basic_auth('user', 'pass')
conn.get('/foo')
Sorry for the trouble. ๋ฌธ์ ๋ฅผ ์ผ์ผ์ผ์ ๋ฏธ์ ํด์.
enThanks for the pointers, all! ํฌ์ธํฐ ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค. It helped me get things working. ์ผ์ด ์ ํ๋ฆฌ๋ ๋ฐ ๋์์ด ๋์์ต๋๋ค. โค๏ธโค๏ธโค๏ธ โค๏ธโค๏ธโค๏ธ
On Tuesday, October 6, 2015, Mislav Marohniฤ [email protected] 2015๋
10์ 6์ผ ํ์์ผ, Mislav Marohniฤ [email protected]
wrote: ์ผ๋ค:
enThanks @OI https://github.com/OI for the helpful examples. ์ ์ฉํ ์์ ๋ฅผ ์ ๊ณตํ @OI https://github.com/OI ์ ๊ฐ์ฌ๋๋ฆฝ๋๋ค.
@jordansissel https://github.com/jordansissel For now, please use this @jordansissel https://github.com/jordansissel ์ง๊ธ์ ์ด๊ฒ์ ์ฌ์ฉํด ์ฃผ์ธ์
form: ํํ:conn = Faraday.new('http://example.com') conn = Faraday.new('http://example.com')
conn.basic_auth('user', 'pass') conn.basic_auth('์ฌ์ฉ์', 'ํต๊ณผ')
conn.get('/foo') conn.get('/foo')Sorry for the trouble. ๋ฌธ์ ๋ฅผ ์ผ์ผ์ผ์ ๋ฏธ์ ํด์.
โ โ
Reply to this email directly or view it on GitHub ์ด ์ด๋ฉ์ผ์ ์ง์ ๋ต์ฅํ๊ฑฐ๋ GitHub์์ ํ์ธํ์ธ์.
https://github.com/lostisland/faraday/issues/426#issuecomment -145914646. https://github.com/lostisland/faraday/issues/426#issuecomment -145914646.
์ด๊ฒ์ ๋ํ #343์ผ๋ก ๋ณด๊ณ ๋์์ต๋๋ค.
en๋ ๊ฐ๋จ:
Faraday.get('http://localhost:3000', nil, authorization: "Bearer 1123")
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
๋ ๊ฐ๋จ:
enFaraday.get('http://localhost:3000', nil, authorization: "Bearer 1123")