Module: Jimmu
- Defined in:
- lib/jimmu.rb,
lib/jimmu.rb,
lib/jimmu.rb,
lib/jimmu.rb,
lib/jimmu.rb,
lib/jimmu.rb,
lib/jimmu.rb,
lib/jimmu.rb
Defined Under Namespace
Modules: BodyParser, CLI, DSL, Router, SQLite3FFI, WebSocketProtocol Classes: Application, ConfigError, Context, CookieJar, Database, DatabaseError, Error, Request, SessionStore, UploadedFile, WebSocketConnection
Constant Summary collapse
- VERSION =
'1.0.0'- HALT =
Internal symbol used with
throw/catchto unwind out of ERB evaluation as soon as a response-terminating DSL method (redirect / json / text / html / render) is called. This is a lightweight, non-exception based control-flow jump: the methods that call it have already recorded the final status/headers/body on the Context object before throwing, so the catch site simply reads those back off the Context. :jimmu_halt- MAX_BODY_SIZE =
Maximum accepted request body size (form posts / uploads), in bytes. This exists purely as a safety net against a client claiming an enormous Content-Length; it is not a tuning knob most apps need to touch. 50 MB is generous for a "small-to-medium" app.
50 * 1024 * 1024
- MIME_TYPES =
File extension -> MIME type, used for static file serving.
{ '.html' => 'text/html; charset=utf-8', '.htm' => 'text/html; charset=utf-8', '.css' => 'text/css; charset=utf-8', '.js' => 'text/javascript; charset=utf-8', '.mjs' => 'text/javascript; charset=utf-8', '.json' => 'application/json; charset=utf-8', '.txt' => 'text/plain; charset=utf-8', '.xml' => 'application/xml; charset=utf-8', '.csv' => 'text/csv; charset=utf-8', '.md' => 'text/markdown; charset=utf-8', '.png' => 'image/png', '.jpg' => 'image/jpeg', '.jpeg' => 'image/jpeg', '.gif' => 'image/gif', '.svg' => 'image/svg+xml', '.webp' => 'image/webp', '.ico' => 'image/x-icon', '.bmp' => 'image/bmp', '.woff' => 'font/woff', '.woff2' => 'font/woff2', '.ttf' => 'font/ttf', '.otf' => 'font/otf', '.eot' => 'application/vnd.ms-fontobject', '.mp3' => 'audio/mpeg', '.wav' => 'audio/wav', '.ogg' => 'audio/ogg', '.mp4' => 'video/mp4', '.webm' => 'video/webm', '.pdf' => 'application/pdf', '.zip' => 'application/zip', '.wasm' => 'application/wasm', '.map' => 'application/json; charset=utf-8' }
- STATUS_PHRASES =
HTTP status code -> reason phrase.
{ 100 => 'Continue', 101 => 'Switching Protocols', 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 204 => 'No Content', 206 => 'Partial Content', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 307 => 'Temporary Redirect', 308 => 'Permanent Redirect', 400 => 'Bad Request', 401 => 'Unauthorized', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 408 => 'Request Timeout', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 413 => 'Payload Too Large', 414 => 'URI Too Long', 415 => 'Unsupported Media Type', 422 => 'Unprocessable Entity', 426 => 'Upgrade Required', 429 => 'Too Many Requests', 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Timeout' }.freeze
- BUILTIN_ERROR_CSS =
<<~CSS.freeze body{margin:0;padding:0;background:#1e1f26;color:#e8e8ec;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif} .jimmu-error{max-width:760px;margin:6vh auto;padding:0 24px} .jimmu-error h1{font-size:22px;color:#ff6b6b;border-bottom:1px solid #34353f;padding-bottom:14px;margin-bottom:18px} .jimmu-error p{line-height:1.6;color:#c3c4cf} .jimmu-error-class{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:14px;background:#2a2b35;padding:10px 14px;border-radius:6px;color:#ffb1b1} .jimmu-error-trace{background:#26272f;border-radius:6px;padding:16px;overflow-x:auto;font-size:12.5px;line-height:1.6;color:#9fa3b5} .jimmu-error-hint{font-size:13px;color:#767a8c;margin-top:20px} .jimmu-error a{color:#7aa2ff} CSS
Class Attribute Summary collapse
-
.application ⇒ Object
The single Application instance that app.rb's top-level DSL calls (port, before, websocket, run, ...) delegate to.
Class Method Summary collapse
-
.percent_decode(str) ⇒ Object
Percent-decode a URL path segment (
%XXsequences only; unlike form/query decoding,+is left as a literal plus in paths). - .status_phrase(code) ⇒ Object
Class Attribute Details
.application ⇒ Object
The single Application instance that app.rb's top-level DSL
calls (port, before, websocket, run, ...) delegate to. Set by
Application#load_app_file just before loading app.rb.
40 41 42 |
# File 'lib/jimmu.rb', line 40 def application @application end |
Class Method Details
.percent_decode(str) ⇒ Object
Percent-decode a URL path segment (%XX sequences only; unlike
form/query decoding, + is left as a literal plus in paths).
127 128 129 |
# File 'lib/jimmu.rb', line 127 def self.percent_decode(str) str.gsub(/%([0-9A-Fa-f]{2})/) { [Regexp.last_match(1)].pack('H2') } end |
.status_phrase(code) ⇒ Object
121 122 123 |
# File 'lib/jimmu.rb', line 121 def self.status_phrase(code) STATUS_PHRASES[code.to_i] || 'Unknown Status' end |