lib/appsignal/transmitter.rb in appsignal-0.5.5 vs lib/appsignal/transmitter.rb in appsignal-0.6.0.beta.1
- old
+ new
@@ -1,13 +1,17 @@
require 'net/http'
require 'net/https'
require 'uri'
-require 'json'
require 'rack/utils'
module Appsignal
class Transmitter
+ CONTENT_TYPE = 'application/json; charset=UTF-8'.freeze
+ CONTENT_ENCODING = 'gzip'.freeze
+ CA_FILE_PATH = File.
+ expand_path(File.join(__FILE__, '../../../resources/cacert.pem'))
+
attr_reader :endpoint, :action, :api_key
def initialize(endpoint, action, api_key, logger=nil)
@endpoint = endpoint
@action = action
@@ -28,26 +32,24 @@
http_client.request(http_post(payload)).code
end
protected
- def ca_file_path
- File.expand_path(File.join(__FILE__, '../../../resources/cacert.pem'))
- end
-
def http_post(payload)
- Net::HTTP::Post.new(uri.request_uri).tap do |post|
- post['Content-Type'] = 'application/json; charset=UTF-8'
- post.body = JSON.generate(payload)
+ Net::HTTP::Post.new(uri.request_uri).tap do |request|
+ request['Content-Type'] = CONTENT_TYPE
+ request['Content-Encoding'] = CONTENT_ENCODING
+ request.body = Zlib::Deflate.
+ deflate(Appsignal.json.encode(payload), Zlib::BEST_SPEED)
end
end
def http_client
Net::HTTP.new(uri.host, uri.port).tap do |http|
if uri.scheme == 'https'
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
- http.ca_file = ca_file_path
+ http.ca_file = CA_FILE_PATH
end
end
end
end
end