Sha256: cab25e39f9d8fa634f4e040adc1cd0a46a90e38f828005fba5955c9fef69b084

Contents?: true

Size: 1 KB

Versions: 9

Compression:

Stored size: 1 KB

Contents

#!/usr/bin/env ruby
$:<< '../lib' << 'lib'
require 'goliath'

class EarlyAbort < Goliath::API
  include Goliath::Validation

  MAX_SIZE = 10
  TEST_FILE = "/tmp/goliath-test-error.log"

  def on_headers(env, headers)
    env.logger.info 'received headers: ' + headers.inspect
    env['async-headers'] = headers

    if env['HTTP_X_CRASH'] && env['HTTP_X_CRASH'] == 'true'
      raise Goliath::Validation::NotImplementedError.new(
          "Can't handle requests with X-Crash: true.")
    end
  end

  def on_body(env, data)
    env.logger.info 'received data: ' + data
    (env['async-body'] ||= '') << data
    size = env['async-body'].size

    if size >= MAX_SIZE
      raise Goliath::Validation::BadRequestError.new(
          "Payload size can't exceed #{MAX_SIZE} bytes. Received #{size.inspect} bytes.")
    end
  end

  def on_close(env)
    env.logger.info 'closing connection'
  end

  def response(env)
    File.open(TEST_FILE, "w+") { |f| f << "response that should not be here\n"}
    [200, {}, "OK"]
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
goliath-1.0.7 examples/early_abort.rb
goliath-1.0.6 examples/early_abort.rb
goliath-1.0.5 examples/early_abort.rb
goliath-1.0.4 examples/early_abort.rb
goliath-1.0.3 examples/early_abort.rb
goliath-1.0.2 examples/early_abort.rb
goliath-1.0.1 examples/early_abort.rb
goliath-1.0.0 examples/early_abort.rb
goliath-1.0.0.beta.1 examples/early_abort.rb