Faraday: Faraday.get ๋ฐ ๊ธฐ๋ณธ ์ธ์ฆ

์— ๋งŒ๋“  2014๋…„ 10์›” 23์ผ  ยท  5์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: lostisland/faraday

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. ์“ฐ๊ธฐ ๋ฐฉํ–ฅ์„ ์•Œ๋ ค์ฃผ์‹œ๋ฉด ์ด ๋ฐฉ๋ฒ•์— ๋Œ€ํ•œ ๋ฌธ์„œ๋ฅผ ์ž‘์„ฑํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

en

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

๋” ๊ฐ„๋‹จ:
Faraday.get('http://localhost:3000', nil, authorization: "Bearer 1123")

en

๋ชจ๋“  5 ๋Œ“๊ธ€

There 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 ์˜ค์ด

en

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. ๋ฌธ์ œ๋ฅผ ์ผ์œผ์ผœ์„œ ๋ฏธ์•ˆ ํ•ด์š”.

en

Thanks 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: ์ผ๋‹ค:

Thanks @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.

en

์ด๊ฒƒ์€ ๋˜ํ•œ #343์œผ๋กœ ๋ณด๊ณ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

en

๋” ๊ฐ„๋‹จ:
Faraday.get('http://localhost:3000', nil, authorization: "Bearer 1123")

en
์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰