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

response data 가 nil 로 반환됩니다 #4

Closed
say8425 opened this issue Apr 20, 2020 · 3 comments
Closed

response data 가 nil 로 반환됩니다 #4

say8425 opened this issue Apr 20, 2020 · 3 comments

Comments

@say8425
Copy link

say8425 commented Apr 20, 2020

안녕하세요. 어떻게 사용해야할지 모르겠어서, 직접 라이브러리 코드를 뜯어서 사용했습니다.
그런데 제가 올바르게 사용했는지 모르겠어서 이슈 남겨드립니다.

Clayful.config['client'] = '클라이언트키'
Clayful::Collection.count
=> Clayful::Exception: 
from /Users/penguin/.asdf/installs/ruby/2.6.3/lib/ruby/gems/2.6.0/gems/clayful-2.2.0/lib/requester.rb:64:in `block in <class:Requester>'

client 로 client 키를 넘겨주면 될거라 생각하고 했는데, 에러가 발생했습니다.
그래서 코드를 보니까 client 가 최종적으로 Authorization 으로 넘겨주는 것을 발견하고,
Authorization 에 직접 client 키르 넘겨줬습니다.

Clayful.config['Authorization'] = '클라이언트키'
Clayful::Collection.count
=> #<Clayful::Response:0x00007ffc1f678ae0
 @data=nil,
 @headers=
  {:access_control_allow_credentials=>"true",
   :access_control_expose_headers=>"WWW-Authenticate,Server-Authorization,content-currency,content-time-zone",
   :cache_control=>"no-cache",
   :content_currency=>"KRW",
   :content_encoding=>"gzip",
   :content_language=>"ko",
   :content_time_zone=>"Asia/Seoul",
   :content_type=>"application/json; charset=utf-8",
   :date=>"Mon, 20 Apr 2020 06:43:19 GMT",
   :server=>"nginx/1.14.1",
   :vary=>"origin,accept-encoding",
   :transfer_encoding=>"chunked",
   :connection=>"keep-alive"},
 @status=200>
Clayful::Collection.count.data
=> nil

이렇게 하니까 200 OK 가 떨어졌지만, data 가 nil 을 반환하였습니다.
혹시 잘못 호출한 코드나 있나요?
고맙습니다.

@say8425
Copy link
Author

say8425 commented Apr 22, 2020

clayful gem 에서 사용중인 rest-client gem 의 2.1.0 버전에,
현재 string 이 이상하게 나오는 이슈가 있는데, 이것과 관련이 있어보입니다.

이슈 코멘트에 언급된데로 accept_encoding: '*'를 사용하니까 정상작동 합니다.
아마도 accept_encoding: 'gzip' 에 이슈 있는 거 같습니다.

결론적으로 아래와 같이 사용하면 작동이 됩니다.

Clayful.config['Authorization'] = '클라이언트키'
Clayful.config['Accept-Encoding'] = '*'
Clayful::Collection.count
=> #<Clayful::Response:0x00007fcf9afb65a0
 @data={"count"=>{"raw"=>148, "formatted"=>"148", "converted"=>"148"}},
 @headers=
  {:accept_ranges=>"bytes",
   :access_control_allow_credentials=>"true",
   :access_control_expose_headers=>
    "WWW-Authenticate,Server-Authorization,content-currency,content-time-zone",
   :cache_control=>"no-cache",
   :content_currency=>"KRW",
   :content_language=>"ko",
   :content_time_zone=>"Asia/Seoul",
   :content_type=>"application/json; charset=utf-8",
   :date=>"Wed, 22 Apr 2020 11:26:06 GMT",
   :server=>"nginx/1.14.1",
   :vary=>"origin,accept-encoding",
   :content_length=>"57",
   :connection=>"keep-alive"},
 @status=200>
Clayful::Collection.count.data
=> {"count"=>{"raw"=>148, "formatted"=>"148", "converted"=>"148"}}

아니면 rest-client gem 2.1.0 버전에만 해당 이슈가 있어 보이므로,
clayful.gemspec에서 rest-client gem dependency를 2.0.x 대로 고정하는 것도 하나의 방법이 될 거 같습니다.

s.add_runtime_dependency 'rest-client', '~> 2.0.1'

@Daeik
Copy link
Contributor

Daeik commented Apr 23, 2020

말씀해주신 대로 2.1.0으로 업그레이드를 진행하고 디코딩 문제를 해결하거나, 2.0.1 버전으로 고정하는 방법을 감안해봐야할 것 같습니다. 내부적으로 한번 검토해보고 패칭 진행하도록 하겠습니다.

이슈 남겨주셔서 감사합니다!

Daeik added a commit that referenced this issue Apr 28, 2020
- 테스트 디펜던시 `fakeweb` 동작이 깨지던 부분을 `fakeweb-fi` 모듈로 마이그레이션 (chrisk/fakeweb#57 (comment))
- `rest-client` `2.1>=` 버전에서 `gzip` `Accept-Encoding` 헤더를 제대로 처리하지 못해 반환 데이터가 제대로 잡히지 않던 현상 수정 (#4)
@Daeik
Copy link
Contributor

Daeik commented Apr 28, 2020

@say8425 리포트해주신 이슈 관련하여 수정된 v2.2.1 버전 릴리즈 되었습니다!

rest-clientv2.1.0으로 업그레이드하고, 제안해주신 Accept-Encoding 헤더를 *로 설정하였습니다.

@Daeik Daeik closed this as completed Apr 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants