Module: Hyperion::Headers
- Included in:
- Hyperion, Hyperion, FakeServer, FakeServer::Config, ResponseDescriptor
- Defined in:
- lib/hyperion/headers.rb
Constant Summary collapse
- ContentTypes =
[[:json, 'application/json'], [:protobuf, 'application/x-protobuf'], [Multipart.format, Multipart.content_type]]
Instance Method Summary collapse
- #content_type_for(format) ⇒ Object
- #format_for(content_type) ⇒ Object
-
#route_headers(route) ⇒ Object
constructs and destructures HTTP headers.
- #short_mimetype(response_descriptor) ⇒ Object
Instance Method Details
#content_type_for(format) ⇒ Object
33 34 35 36 37 |
# File 'lib/hyperion/headers.rb', line 33 def content_type_for(format) format = Hyperion::Formats.get_from(format) ct = ContentTypes.detect{|x| x.first == format} ct ? ct.last : 'application/octet-stream' end |
#format_for(content_type) ⇒ Object
39 40 41 42 43 |
# File 'lib/hyperion/headers.rb', line 39 def format_for(content_type) ct = ContentTypes.detect{|x| x.last == content_type.split(';')[0]} fail "Unsupported content type: #{content_type}" unless ct ct.first end |
#route_headers(route) ⇒ Object
constructs and destructures HTTP headers
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/hyperion/headers.rb', line 8 def route_headers(route) headers = Logatron.http_headers rd = route.response_descriptor pd = route.payload_descriptor headers['Expect'] = nil # this overrides default libcurl behavior. # see http://devblog.songkick.com/2012/11/27/a-second-here-a-second-there/ # and http://stackoverflow.com/questions/17383089/libcurl-delays-for-1-second-before-uploading-data-command-line-curl-does-not if rd headers['Accept'] = "application/vnd.#{Hyperion.config.vendor_string}.#{short_mimetype(rd)}" end if pd headers['Content-Type'] = content_type_for(pd.format) end headers end |
#short_mimetype(response_descriptor) ⇒ Object
24 25 26 27 |
# File 'lib/hyperion/headers.rb', line 24 def short_mimetype(response_descriptor) x = response_descriptor "#{x.type}-v#{x.version}+#{x.format}" end |