Fixnum 인스턴스를 헤더의 값으로 전달하면 가상 서버 오류가 발생합니다.

5866 단어 thin

묘사

다음 리소스를 고려합니다.
module MyApp
  module Endpoints
    class Search < Grape::API
      helpers Helpers::Parameters

      resource 'search/people' do
        desc 'Finds people by their registered documents'
        params { use :search_by_documents }
        post do
          people = Models::Profile.matching_any_document(params[:documents])

          header 'X-Results-Count', people.count
          present people, with: Entities::Person::Compact
        end
      end
    end
  end
end
응답 헤더 header 'X-Results-Count', people.count 를 전달하고 있는데, 그 중 people.countFixnum 로 되돌아오는 실례가 있습니다.이 응답으로 인해 가상 버전에서 다음 오류가 발생합니다.
api_1      | Unexpected error while processing request: undefined method `each' for 1:Fixnum
api_1      |    /opt/sabes_api/vendor/bundle/ruby/2.3.0/gems/thin-1.7.0/lib/thin/response.rb:74:in `block in headers='
api_1      |    /opt/sabes_api/vendor/bundle/ruby/2.3.0/gems/rack-1.6.5/lib/rack/utils.rb:501:in `block in each'
api_1      |    /opt/sabes_api/vendor/bundle/ruby/2.3.0/gems/rack-1.6.5/lib/rack/utils.rb:500:in `each'
api_1      |    /opt/sabes_api/vendor/bundle/ruby/2.3.0/gems/rack-1.6.5/lib/rack/utils.rb:500:in `each'
api_1      |    /opt/sabes_api/vendor/bundle/ruby/2.3.0/gems/thin-1.7.0/lib/thin/response.rb:69:in `headers='
api_1      |    /opt/sabes_api/vendor/bundle/ruby/2.3.0/gems/thin-1.7.0/lib/thin/connection.rb:102:in `post_process'
api_1      |    /opt/sabes_api/vendor/bundle/ruby/2.3.0/gems/thin-1.7.0/lib/thin/connection.rb:53:in `process'
api_1      |    /opt/sabes_api/vendor/bundle/ruby/2.3.0/gems/thin-1.7.0/lib/thin/connection.rb:39:in `receive_data'
api_1      |    /opt/sabes_api/vendor/bundle/ruby/2.3.0/gems/eventmachine-1.2.1/lib/eventmachine.rb:194:in `run_machine'
api_1      |    /opt/sabes_api/vendor/bundle/ruby/2.3.0/gems/eventmachine-1.2.1/lib/eventmachine.rb:194:in `run'
api_1      |    /opt/sabes_api/vendor/bundle/ruby/2.3.0/gems/thin-1.7.0/lib/thin/backends/base.rb:73:in `start'
api_1      |    /opt/sabes_api/vendor/bundle/ruby/2.3.0/gems/thin-1.7.0/lib/thin/server.rb:162:in `start'
api_1      |    /opt/sabes_api/vendor/bundle/ruby/2.3.0/gems/thin-1.7.0/lib/thin/controllers/controller.rb:87:in `start'
api_1      |    /opt/sabes_api/vendor/bundle/ruby/2.3.0/gems/thin-1.7.0/lib/thin/runner.rb:200:in `run_command'
api_1      |    /opt/sabes_api/vendor/bundle/ruby/2.3.0/gems/thin-1.7.0/lib/thin/runner.rb:156:in `run!'
api_1      |    /opt/sabes_api/vendor/bundle/ruby/2.3.0/gems/thin-1.7.0/bin/thin:6:in `<top (required)>'
api_1      |    /opt/sabes_api/vendor/bundle/ruby/2.3.0/bin/thin:22:in `load'
api_1      |    /opt/sabes_api/vendor/bundle/ruby/2.3.0/bin/thin:22:in `<top (required)>'
api_1      |    /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/lib/bundler/cli/exec.rb:74:in `load'
api_1      |    /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/lib/bundler/cli/exec.rb:74:in `kernel_load'
api_1      |    /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/lib/bundler/cli/exec.rb:27:in `run'
api_1      |    /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/lib/bundler/cli.rb:332:in `exec'
api_1      |    /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
api_1      |    /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
api_1      |    /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/lib/bundler/vendor/thor/lib/thor.rb:359:in `dispatch'
api_1      |    /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/lib/bundler/cli.rb:20:in `dispatch'
api_1      |    /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/lib/bundler/vendor/thor/lib/thor/base.rb:440:in `start'
api_1      |    /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/lib/bundler/cli.rb:11:in `start'
api_1      |    /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/exe/bundle:34:in `block in <top (required)>'
api_1      |    /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/lib/bundler/friendly_errors.rb:100:in `with_friendly_errors'
api_1      |    /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/exe/bundle:26:in `<top (required)>'
api_1      |    /usr/local/bundle/bin/bundle:22:in `load'
api_1      |    /usr/local/bundle/bin/bundle:22:in `<main>'
제목을 header 'X-Results-Count', people.count.to_s (주의 people.count 로 변경했을 때, 모든 것이 정상입니다.
내가 읽은Grape 문서에 대해 말하자면, 헤더에 대한 값은 문자열의 참고가 될 것 같지 않다.
JSYK: 저는 docker imageruby:2.3.3-slim를 사용하고 있습니다. 이것은 제 파일입니다.
source 'https://rubygems.org'

gem 'grape', '~> 0.19.1'
gem 'grape-entity', '~> 0.6.1'
gem 'mongoid', '~> 6.0.3'
gem 'rack', '~> 1.5'
gem 'rake', '~> 11.3.0'
gem 'sentry-raven', '~> 2.2.0'
gem 'thin', '~> 1.7.0'

group :development, :testing, :staging do
  gem 'activesupport', '~> 5.0.1'
  gem 'json', '~> 2.0.3'
  gem 'rack-test', '~> 0.6.3'
  gem 'rspec', '~> 3.5.0'
  gem 'rubocop', '~> 0.45.0'
  gem 'rubycritic', '~> 3.1.3'
  gem 'simplecov', '~> 0.12.0'
end

토론 #1

랙 사양에 따라 헤더의 값은 문자열이어야 합니다.http://www.rubydoc.info/github/rack/rack/master/file/SPEC, 대부분의 씬 서버에서 사용됩니다.

토론 #2

오, 그래.
정보를 제공해 주셔서 감사합니다.

좋은 웹페이지 즐겨찾기