Module: Goliath

Defined in:
lib/goliath/goliath.rb,
lib/goliath/api.rb,
lib/goliath/env.rb,
lib/goliath/rack.rb,
lib/goliath/runner.rb,
lib/goliath/server.rb,
lib/goliath/console.rb,
lib/goliath/headers.rb,
lib/goliath/request.rb,
lib/goliath/version.rb,
lib/goliath/response.rb,
lib/goliath/constants.rb,
lib/goliath/websocket.rb,
lib/goliath/connection.rb,
lib/goliath/rack/jsonp.rb,
lib/goliath/rack/types.rb,
lib/goliath/application.rb,
lib/goliath/rack/params.rb,
lib/goliath/rack/render.rb,
lib/goliath/rack/tracer.rb,
lib/goliath/test_helper.rb,
lib/goliath/rack/builder.rb,
lib/goliath/rack/favicon.rb,
lib/goliath/rack/heartbeat.rb,
lib/goliath/rack/templates.rb,
lib/goliath/rack/validator.rb,
lib/goliath/test_helper_ws.rb,
lib/goliath/plugins/latency.rb,
lib/goliath/rack/formatters.rb,
lib/goliath/rack/types/base.rb,
lib/goliath/rack/types/core.rb,
lib/goliath/rack/validation.rb,
lib/goliath/test_helper_sse.rb,
lib/goliath/validation/error.rb,
lib/goliath/http_status_codes.rb,
lib/goliath/rack/types/symbol.rb,
lib/goliath/rack/types/boolean.rb,
lib/goliath/rack/formatters/xml.rb,
lib/goliath/rack/formatters/html.rb,
lib/goliath/rack/formatters/json.rb,
lib/goliath/rack/formatters/yaml.rb,
lib/goliath/rack/async_middleware.rb,
lib/goliath/rack/formatters/plist.rb,
lib/goliath/rack/validation/param.rb,
lib/goliath/test_helper_streaming.rb,
lib/goliath/rack/default_mime_type.rb,
lib/goliath/rack/simple_aroundware.rb,
lib/goliath/rack/validation/coerce.rb,
lib/goliath/rack/barrier_aroundware.rb,
lib/goliath/rack/validation/required.rb,
lib/goliath/rack/default_response_format.rb,
lib/goliath/rack/validation/boolean_value.rb,
lib/goliath/rack/validation/numeric_range.rb,
lib/goliath/rack/simple_aroundware_factory.rb,
lib/goliath/rack/validation/default_params.rb,
lib/goliath/rack/validation/request_method.rb,
lib/goliath/rack/validation/required_param.rb,
lib/goliath/rack/validation/required_value.rb,
lib/goliath/rack/barrier_aroundware_factory.rb,
lib/goliath/validation/standard_http_errors.rb

Overview

Reads a favicon.ico statically at load time, renders it on any request for ‘/favicon.ico’, and sends every other request on downstream.

Rack::Static is a better option if you’re serving several static assets.

Defined Under Namespace

Modules: Constants, Plugin, Rack, TestHelper, Validation Classes: API, Env, EnvironmentParser, Runner, WebSocket

Constant Summary collapse

DEFAULT_ENV =

The default run environment, should one not be set.

:development
ENVIRONMENTS =
[:development, :production, :test, :staging]
VERSION =

The current version of Goliath

'1.0.6'
HTTP_STATUS_CODES =

Every standard HTTP code mapped to the appropriate message.

Author:

  • Mongrel.

{
  100 => 'Continue',
  101 => 'Switching Protocols',
  200 => 'OK',
  201 => 'Created',
  202 => 'Accepted',
  203 => 'Non-Authoritative Information',
  204 => 'No Content',
  205 => 'Reset Content',
  206 => 'Partial Content',
  300 => 'Multiple Choices',
  301 => 'Moved Permanently',
  302 => 'Moved Temporarily',
  303 => 'See Other',
  304 => 'Not Modified',
  305 => 'Use Proxy',
  400 => 'Bad Request',
  401 => 'Unauthorized',
  402 => 'Payment Required',
  403 => 'Forbidden',
  404 => 'Not Found',
  405 => 'Method Not Allowed',
  406 => 'Not Acceptable',
  407 => 'Proxy Authentication Required',
  408 => 'Request Time-out',
  409 => 'Conflict',
  410 => 'Gone',
  411 => 'Length Required',
  412 => 'Precondition Failed',
  413 => 'Request Entity Too Large',
  414 => 'Request-URI Too Large',
  415 => 'Unsupported Media Type',
  500 => 'Internal Server Error',
  501 => 'Not Implemented',
  502 => 'Bad Gateway',
  503 => 'Service Unavailable',
  504 => 'Gateway Time-out',
  505 => 'HTTP Version not supported'
}
HTTP_ERROR_CODES =

Make a subclass of Goliath::Validation::Error for each standard HTTP error code (4xx and 5xx). Error will have a default status_code and message correct for that response:

err = Goliath::Validation::NotFoundError.new
p [err.status_code, err.to_s]
# => [400, "Not Found"]

Each class is named for the standard HTTP message, so 504 ‘Gateway Time-out’ becomes a Goliath::Validation::GatewayTimeoutError (except ‘Internal Server Error’, which becomes InternalServerError not InternalServerErrorError). All non-alphanumeric characters are smushed together, with no upcasing or downcasing.

HTTP_STATUS_CODES.select { |code,msg| code >= 400 && code <= 599 }

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.run_app_on_exitObject Also known as: run_app_on_exit?

Controls whether or not the application will be run using an at_exit block.



30
31
32
# File 'lib/goliath/goliath.rb', line 30

def run_app_on_exit
  @run_app_on_exit
end

Class Method Details

.envString

Retrieves the current goliath environment

Returns:

  • (String)

    the current environment



39
40
41
# File 'lib/goliath/goliath.rb', line 39

def env
  @env
end

.env=(e) ⇒ Object

Sets the current goliath environment

Parameters:

  • env (String|Symbol)

    the environment symbol



46
47
48
49
50
51
52
# File 'lib/goliath/goliath.rb', line 46

def env=(e)
  @env = case(e.to_sym)
  when :dev  then :development
  when :prod then :production
  else e.to_sym
  end
end

.env?(e) ⇒ Boolean

Determines if we are in a particular environment

Returns:

  • (Boolean)

    true if current environment matches, false otherwise



57
58
59
# File 'lib/goliath/goliath.rb', line 57

def env?(e)
  env == e.to_sym
end