Method: ScalyrThreaded::ScalyrOut#post_request

Defined in:
lib/fluent/plugin/out_scalyr_threaded.rb

#post_request(uri, body) ⇒ Object



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/fluent/plugin/out_scalyr_threaded.rb', line 239

def post_request( uri, body )

  https = Net::HTTP.new( uri.host, uri.port )
  https.use_ssl = true

  #verify peers to prevent potential MITM attacks
  if @ssl_verify_peer
    https.ca_file = @ssl_ca_bundle_path
    https.verify_mode = OpenSSL::SSL::VERIFY_PEER
    https.verify_depth = @ssl_verify_depth
  end

  #use compression if enabled
  encoding = nil

  if @compression_type
    if @compression_type == 'deflate'
      encoding = 'deflate'
      body = Zlib::Deflate.deflate(body, @compression_level)
    elsif @compression_type == 'bz2'
      encoding = 'bz2'
      io = StringIO.new
      bz2 = RBzip2.default_adapter::Compressor.new io
      bz2.write body
      bz2.close
      body = io.string
    end
  end

  post = Net::HTTP::Post.new uri.path
  post.add_field( 'Content-Type', 'application/json' )

  if @compression_type
    post.add_field( 'Content-Encoding', encoding )
  end

  post.body = body

  https.request( post )

end