Skip to content

Instantly share code, notes, and snippets.

@mattetti
Created November 21, 2011 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattetti/1384096 to your computer and use it in GitHub Desktop.
Save mattetti/1384096 to your computer and use it in GitHub Desktop.
interface mimicking some of the Servlet implementation
# TO READ: http://en.wikipedia.org/wiki/Raclette
#
# A request comes in is parsed and made available as an object.
# The response attached to the request is made of 2 objects, a response object and a body (IO).
# The response is dispatched via the RequestDispatcher module which can have filters registered to process it.
# If the response starts being streamed, the response object is immediately frozen and only the body can be changed and flushed.
# When Rack meets Servlet
module Raclette
# Defines an object to provide client request information to a raclette.
# The raclette container creates a Raclette::Request object and passes it as an argument to the raclette's service method.
# A RacletteRequest object provides data including parameter name and values, attributes, and an input stream.
# Interfaces that extend Raclette::Request can provide additional protocol-specific data (for example, HTTP data is provided by Raclette::Http::Request.
class Request
# Returns a Hash of custom attributes set by the processing code.
# This hash is thread safe and available for writing.
# @return [Hash]
def attributes; end
# Returns the name of the character encoding used in the body of this request.
# @return [String]
def character_encoding; end
# Overrides the name of the character encoding used in the body of this request.
# @return [String]
def character_encoding=(val); end
# Returns the length, in bytes, of the request body and made available by the input stream, or -1 if the length is not known.
# @return [Numeric]
def content_length; end
# Returns the MIME type of the body of the request, or null if the type is not known.
# @return [String, NilClass]
def content_type; end
# Retrieves the body of the request as binary data
# @return [IO]
def input_stream; end
# Returns the preferred Locale that the client will accept content in, based on the Accept-Language header.
# @return [String]
def locale; end
# Returns an Enumeration of locales indicating, in decreasing order starting with the preferred locale,
# the locales that are acceptable to the client based on the Accept-Language header.
# @return [Array<String>]
def locales; end
# Returns the parameters of this request.
# @return [Hash]
def params; end
# Returns the name and version of the protocol the request uses in the form protocol/majorVersion.minorVersion,
# for example, HTTP/1.1.
# @return [String]
def protocol; end
# Retrieves the body of the request
# @return [IO]
def body; end
# Returns the Internet Protocol (IP) address of the client that sent the request.
# @return [String]
def remote_addr; end
# Returns the fully qualified name of the client that sent the request.
# @return [String]
def remote_host; end
# Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path.
# @return [RequestDispatcher]
def request_dispatcher; end
# Returns the name of the scheme used to make this request, for example, http, https, or ftp.
# @return [String]
def scheme; end
# Returns the host name of the server that received the request.
# @return [String]
def server_name; end
# Returns the port number on which this request was received.
# @return [Integer]
def server_port; end
# Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS.
# @return [Boolean]
def secure?; end
end
module HTTP
class Request < Raclette::Request
BASIC_AUTH = "BASIC"
FORM_AUTH = "FORM"
CLIENT_CERT_AUTH = "CLIENT_CERT"
DIGEST_AUTH = "DIGEST"
# Returns the name of the authentication scheme used to protect the raclette.
# @return [String]
def auth_type; end
# Returns the portion of the request URI that indicates the context of the request.
# @return [String]
def context_path; end
# Returns an array containing all of the Cookie objects the client sent with this request.
# @return [Cookie]
def cookies; end
# Returns the value of the specified request header as a long value that represents a Date object.
# @return [Numeric]
def date_header; end
# Returns the value of the specified request header as a String.
# @return [String]
def header; end
# Returns an enumeration of all the header names this request contains.
# @return [Array<String>]
def header_names; end
# Returns an enumeration of all the header names this request contains.
# @param [String] name the name of the header to return
# @return [Array<String>]
def headers(name); end
# Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT.
# @return [String]
def method; end
# Returns any extra path information associated with the URL the client sent when it made this request.
# @return [String]
def path_info; end
# Returns any extra path information after the raclette name but before the query string, and translates it to a real path.
# @return [String]
def path_translated; end
# Returns the query string that is contained in the request URL after the path.
# @return [String]
def query_string; end
# Returns the login of the user making this request, if the user has been authenticated, or null if the user has not been authenticated.
# @return [String]
def remote_user; end
# Returns the session ID specified by the client.
# @return [String]
def request_session_id; end
# Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request.
# @return [String]
def request_uri; end
# Reconstructs the URL the client used to make the request.
# @return [String]
def request_url; end
# Returns the part of this request's URL that calls the raclette.
# @return [String]
def raclette_path; end
# Returns the current session associated with this request, or if the request does not have a session,
# and the create param is true, then it creates one.
# @param [Boolean] create
# @return [HttpSession]
def session(create=true); end
# Returns a Security::User object containing the name of the current authenticated user.
# @return [Security::User]
def current_user; end
# Checks whether the requested session ID came in as a cookie.
# @return [Boolean]
def request_session_id_from_cookie?; end
# Checks whether the requested session ID came in as part of the request URL.
# @return [Boolean]
def request_session_id_from_url?; end
# Checks whether the requested session ID is still valid.
# @return [Boolean]
def request_session_valid?; end
# Returns a boolean indicating whether the authenticated user is included in the specified logical "role".
# @return [Boolean]
def current_user_in_role?(role); end
end
end
# Defines an object to assist in sending a response to the client.
class Response
# Indicates if the response is being streamed or not.
# @return [Boolean]
def streamed?; end
# Forces any content in the buffer to be written to the client.
# @return [Boolean]
def flush_buffer; end
# Returns the actual buffer size used for the response.
# @return [Integer]
def buffer_size; end
# Sets the preferred buffer size for the body of the response.
# @return [Integer]
def buffer_size=(val); end
# Returns the name of the charset used for the MIME body sent in this response.
# @return [String]
def character_encoding; end
# Returns the locale assigned to the response.
# @return [String]
def locale; end
# Sets the locale of the response, setting the headers (including the Content-Type's charset) as appropriate.
# @return [String]
def locale=(val); end
# Returns a boolean indicating if the response has been committed.
# @return [Boolean]
def committed?; end
# Clears any data that exists in the buffer as well as the status code and headers.
# @return [Boolean]
def reset; end
# Clears the content of the underlying buffer in the response without clearing headers or status code.
# @return [Boolean]
def reset_buffer; end
# REturns the length of the content body in the response.
# @return [Integer]
def content_length; end
# Sets the length of the content body in the response In HTTP, this method sets the HTTP Content-Length header.
# @return [Integer]
def content_length=(val); end
# Returns the content type of the response being sent to the client.
# @return [String]
def content_type; end
# Sets the content type of the response being sent to the client.
# @return [String]
def content_type=(val); end
end
class HTTP < Response
# Status code (202) indicating that a request was accepted for processing, but was not completed.
ACCEPTED = 202
# Status code (502) indicating that the HTTP server received an invalid response from a server it consulted when acting as a proxy or gateway.
BAD_GATEWAY = 502
# Status code (400) indicating the request sent by the client was syntactically incorrect.
BAD_REQUEST = 400
# Status code (409) indicating that the request could not be completed due to a conflict with the current state of the resource.
CONFLICT = 409
# Status code (100) indicating the client can continue.
CONTINUE = 100
# Status code (201) indicating the request succeeded and created a new resource on the server.
CREATED = 201
# Status code (417) indicating that the server could not meet the expectation given in the Expect request header.
EXPECTATION_FAILED = 417
# Status code (403) indicating the server understood the request but refused to fulfill it.
FORBIDDEN = 403
# Status code (504) indicating that the server did not receive a timely response from the upstream server while acting as a gateway or proxy.
GATEWAY_TIMEOUT = 504
# Status code (410) indicating that the resource is no longer available at the server and no forwarding address is known.
GONE = 410
# Status code (505) indicating that the server does not support or refuses to support the HTTP protocol version that was used in the request message.
HTTP_VERSION_NOT_SUPPORTED = 505
# Status code (500) indicating an error inside the HTTP server which prevented it from fulfilling the request.
INTERNAL_SERVER_ERROR = 500
# Status code (411) indicating that the request cannot be handled without a defined Content-Length.
LENGTH_REQUIRED = 411
# Status code (405) indicating that the method specified in the Request-Line is not allowed for the resource identified by the Request-URI.
METHOD_NOT_ALLOWED = 405
# Status code (301) indicating that the resource has permanently moved to a new location, and that future references should use a new URI with their requests.
MOVED_PERMANENTLY = 301
# Status code (302) indicating that the resource has temporarily moved to another location, but that future references should still use the original URI to access the resource.
MOVED_TEMPORARILY = 302
# Status code (300) indicating that the requested resource corresponds to any one of a set of representations, each with its own specific location.
MULTIPLE_CHOICES = 300
# Status code (204) indicating that the request succeeded but that there was no new information to return.
NO_CONTENT = 204
# Status code (203) indicating that the meta information presented by the client did not originate from the server.
NON_AUTHORITATIVE_INFORMATION = 203
# Status code (406) indicating that the resource identified by the request is only capable of generating response entities which have content characteristics not acceptable according to the accept headers sent in the request.
NOT_ACCEPTABLE = 406
# Status code (404) indicating that the requested resource is not available.
NOT_FOUND = 404
# Status code (501) indicating the HTTP server does not support the functionality needed to fulfill the request.
NOT_IMPLEMENTED = 501
# Status code (304) indicating that a conditional GET operation found that the resource was available and not modified.
NOT_MODIFIED = 304
# Status code (200) indicating the request succeeded normally.
OK = 200
# Status code (206) indicating that the server has fulfilled the partial GET request for the resource.
PARTIAL_CONTENT = 206
# Status code (402) reserved for future use.
PAYMENT_REQUIRED = 402
# Status code (412) indicating that the precondition given in one or more of the request-header fields evaluated to false when it was tested on the server.
PRECONDITION_FAILED = 412
# Status code (407) indicating that the client MUST first authenticate itself with the proxy.
PROXY_AUTHENTICATION_REQUIRED = 407
# Status code (413) indicating that the server is refusing to process the request because the request entity is larger than the server is willing or able to process.
REQUEST_ENTITY_TOO_LARGE = 413
# Status code (408) indicating that the client did not produce a requestwithin the time that the server was prepared to wait.
REQUEST_TIMEOUT = 408
# Status code (414) indicating that the server is refusing to service the request because the Request-URI is longer than the server is willing to interpret.
REQUEST_URI_TOO_LONG = 414
# Status code (416) indicating that the server cannot serve the requested byte range.
REQUESTED_RANGE_NOT_SATISFIABLE = 416
# Status code (205) indicating that the agent SHOULD reset the document view which caused the request to be sent.
RESET_CONTENT = 205
# Status code (303) indicating that the response to the request can be found under a different URI.
SEE_OTHER = 303
# Status code (503) indicating that the HTTP server is temporarily overloaded, and unable to handle the request.
SERVICE_UNAVAILABLE = 503
# Status code (101) indicating the server is switching protocols according to Upgrade header.
SWITCHING_PROTOCOLS = 101
# Status code (307) indicating that the requested resource resides temporarily under a different URI.
TEMPORARY_REDIRECT = 307
# Status code (401) indicating that the request requires HTTP authentication.
UNAUTHORIZED = 401
# Status code (415) indicating that the server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method.
UNSUPPORTED_MEDIA_TYPE = 415
# Status code (305) indicating that the requested resource MUST be accessed through the proxy given by the Location field.
USE_PROXY = 305
end
module RequestDispatcher
module_function
def filter(request, response); end
def register_filter(filter); end
end
module Security
# basic interface representing a system user
class User; end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment