- 浏览: 2072561 次
- 性别:
- 来自: NYC
文章分类
- 全部博客 (628)
- Linux (53)
- RubyOnRails (294)
- HTML (8)
- 手册指南 (5)
- Mysql (14)
- PHP (3)
- Rails 汇总 (13)
- 读书 (22)
- plugin 插件介绍与应用 (12)
- Flex (2)
- Ruby技巧 (7)
- Gem包介绍 (1)
- javascript Jquery ext prototype (21)
- IT生活 (6)
- 小工具 (4)
- PHP 部署 drupal (1)
- javascript Jquery sort plugin 插件 (2)
- iphone siri ios (1)
- Ruby On Rails (106)
- 编程概念 (1)
- Unit Test (4)
- Ruby 1.9 (24)
- rake (1)
- Postgresql (6)
- ruby (5)
- respond_to? (1)
- method_missing (1)
- git (8)
- Rspec (1)
- ios (1)
- jquery (1)
- Sinatra (1)
最新评论
-
dadadada2x:
user模型里加上 protected def email ...
流行的权限管理 gem devise的定制 -
Sev7en_jun:
shrekting 写道var pattern = /^(0| ...
强悍的ip格式 正则表达式验证 -
jiasanshou:
好文章!!!
RPM包rpmbuild SPEC文件深度说明 -
寻得乐中乐:
link_to其实就是个a标签,使用css控制,添加一个参数: ...
Rails在link_to中加参数 -
aiafei0001:
完全看不懂,不知所然.能表达清楚一点?
"$ is not defined" 的问题怎么办
Introducing Rack
Tue Feb 20 18:26:03 CET 2007
Dabbling in my own web framework experiments, I noticed that there is a lot of code duplication among frameworks since they essentially all do the same things. And still, every Ruby web framework developer is writing his own handlers for every webserver he wants to use. Hopefully, the framework users are satisfied with that choice.
However, in essence, dealing with HTTP is rather easy. In the end, you get a request and return a response. Let’s do the easiest thing possible: The canonical format of a HTTP request probably is a hash of a CGI-like environment (that’s what most frameworks I’ve looked at deal with, internally), and a response consists of three parts: a status, a set of headers, and a body.
This could be easily mapped onto a method call in Ruby, looking like this:
class HelloWorld
def call(env)
[200, {"Content-Type" => "text/plain"}, ["Hello world!"]]
end
end
You’ve just seen the most simple Rack application.
Rack aims to provide a minimal API for connecting web servers and web frameworks.
Informally, a Rack application
is a thing that responds to #call
and
takes a hash as argument, returning an array of status, headers and a
body. The body needs to respond to #each
and then successively
return strings that represent the response body. The hash given
contains a CGI-ish set of environment variables and some special
values, like the body stream of the request (env['rack.input']
),
or information about the run-time environment (e.g. env['rack.run_once']
).
Please note that this API is mainly used by framework developers and
usually will not be exposed to framework users. It may seem a bit
clumsy at first, or you may have expected a more “polished” API, but
the important thing is that the API is very simple (notice that it
even can be satisfied by a lambda
) and not hard to adopt.
(The Camping adapter is a mere five lines of code.)
On top of this minimal API, there are libraries for commonly used
things like query parsing or cookie handling and provide more
convenience (Rack::Request
and Rack::Response
) that you are free
to use if you wish.
But the really cool thing about Rack is that it provides an extremely
easy way to combine these web applications. After all, they are only
Ruby objects with a single method that matters. And the thing that
call
s you must not really be a web server, but could as well be a
different application! Let me show you a few Rack filters (or
“middleware”) that already exist:
-
Rack::ShowExceptions
catches all thrown exceptions and wraps them nicely in an helpful 500-page adapted from Django. -
Rack::CommonLogger
does Apache-style logs. -
Rack::URLMap
redirects to different Rack applications depending on the path and host (a very simple router).
There is another tool, Rack::Lint
that checks if your applications
and filters play nicely with others so everything ought to work together.
What do you gain if your web framework/server/application supports Rack?
-
Handlers for WEBrick, Mongrel and plain CGI (soon FastCGI, too), and every new webserver that provides a Rack handler. (Let n and m be the amount of servers and frameworks, without Rack it’s n*m, but with it’s n+m, which means less work for everyone.)
-
The possibility to run several applications inside a single webserver without external configuration.
-
Easier (integration and functional) testing, since everything can easily be mocked. (Helpers for this are coming soon, too.)
-
A greater diversity among frameworks, since writers now can concentrate on the parts that make it special and stop wasting their time on boring things.
-
More synergistic effects: Compare “That upload handler you wrote for IOWA is really great, too bad I use Camping.” with “That upload handler you wrote for Rack works great for me too!”
Currently, Rack is supported by Camping (adapter included with Rack) and Ramaze , more adapters are in the works (a Rails one would be a really cool contribution, hint, hint).
(If you are into Python, you’ll notice a lot of similarities between Rack and WSGI and Paste . That’s fully intended, as I think WSGI helped the Python web landscape really a lot.)
A Rubyforge project has been requested, and a first release will happen really soon. If you’d like to help, contact me by mail or via IRC (chris2@#ruby-lang on FreeNode).
发表评论
-
Destroying a Postgres DB on Heroku
2013-04-24 10:58 928heroku pg:reset DATABASE -
VIM ctags setup ack
2012-04-17 22:13 3255reference ctags --extra=+f --e ... -
alias_method_chain方法在3.1以后的替代使用方式
2012-02-04 02:14 3288alias_method_chain() 是rails里的一个 ... -
一些快速解决的问题
2012-01-19 12:35 1470问题如下: 引用Could not open library ... -
API service 安全问题
2011-12-04 08:47 1380这是一个长期关注的课题 rest api Service的 ... -
Module方法调用好不好
2011-11-20 01:58 1344以前说,用module给class加singleton方法,和 ... -
一个ajax和rails交互的例子
2011-11-19 01:53 1903首先,这里用了一个,query信息解析的包,如下 https: ... -
Rails 返回hash给javascript
2011-11-19 01:43 2272这是一个特别的,不太正统的需求, 因为,大部分时候,ajax的 ... -
关于Rubymine
2011-11-18 23:21 2263开个帖子收集有关使用上的问题 前一段时间,看到半价就买了。想 ... -
ruby中和javascript中,动态方法的创建
2011-11-18 21:01 1234class Klass def hello(*args) ... -
textmate快捷键 汇总
2011-11-16 07:20 8138TextMate 列编辑模式 按住 Alt 键,用鼠标选择要 ... -
Ruby面试系列六,面试继续面试
2011-11-15 05:55 2018刚才受到打击了,充分报漏了自己基础不扎实,不肯向虎炮等兄弟学习 ... -
说说sharding
2011-11-13 00:53 1481这个东西一面试就有人 ... -
rails面试碎碎念
2011-11-12 23:51 1939面试继续面试 又有问ru ... -
最通常的git push reject 和non-fast forward是因为
2011-11-12 23:29 17209git push To git@github.com:use ... -
Rails 自身的many to many关系 self has_many
2011-11-12 01:43 2732简单点的 #注意外键在person上people: id ... -
Rails 3下的 in place editor edit in place
2011-11-12 01:20 945第一个版本 http://code.google.com/p ... -
Heroku 的诡异问题集合
2011-11-11 07:22 1692开个Post记录,在用heroku过程中的一些诡异问题和要注意 ... -
SCSS 和 SASS 和 HAML 和CoffeeScript
2011-11-07 07:52 12952Asset Pipeline 提供了内建 ... -
Invalid gemspec because of the date format in specification
2011-11-07 02:14 2115又是这个date format的错误。 上次出错忘了,记录下 ...
相关推荐
### Ruby on Rails中Rack中间件的基础学习教程 #### 一、Rack简介 Rack是一种轻量级的Web服务器接口规范,它定义了Web服务器和Web应用之间的接口,使得不同的Web应用能够运行在同一服务器上。Rack的重要性在于它...
OmniAuth 就是一个 Rack 中间件,它可以插在 Web 应用程序的请求处理流程中,负责处理与用户认证相关的任务。 OmniAuth 的核心设计原则是模块化和可扩展性。它允许开发者定义多个“策略”(strategies),每个策略...
标题中的“用于检查应用程序健康状况的简单Rack中间件”是指一种基于Ruby的Web服务器接口——Rack。Rack是一个规范,它定义了Ruby web应用和web服务器之间的接口,允许不同的框架和服务器之间进行交互。这个中间件是...
在IT行业中,Rack是一个非常重要的组件,尤其是在Ruby on Rails框架中。Rack是一个轻量级的接口,它定义了Web服务器如何与Ruby应用程序进行通信。这个“作为Rack中间件的健康检查页面”指的是使用Rack中间件来创建一...
rack-zippy v4 +是Rack中间件,用于在不是Rails 4.2+应用程序的Rack应用程序中提供.gz文件。 (如果需要在Rails <= 4.1应用程序中使用rack-zippy,然后使用v3.0的rack-zippy,请在此处查看自述文件: : ) rack-...
这提供了Rack中间件和Rails ActionController过滤器,用于将HTTP请求-响应对记录到HAR文件中。 安装 将此行添加到您的应用程序的Gemfile中: gem 'akita-har_logger' 然后执行: $ bundle install 或将其自己安装...
Ruby-Garner是一个针对Ruby开发者的工具包,它包含了Rack中间件和一系列辅助方法,旨在帮助开发者实施高效的缓存策略。在Web开发中,缓存是提高性能的关键技术,它可以减少服务器处理请求的负担,加快用户访问速度,...
Rack :: Authorize是用于授权api访问的Rack中间件。 我们知道有Cancan,它是Ruby on Rails的出色授权库。 但是Cancan的规则是为Ruby Class定义的,当我们创建Web服务时,限制对api端点的访问是一项常见的任务。 这...
OmniAuth是一个强大的身份验证解决方案,它利用了Rack中间件的灵活性,为Ruby on Rails和其他使用Rack的应用程序提供了一种标准化的方式处理多种身份验证服务。Rack是Ruby web服务器接口,允许开发者构建自己的web...
这会将代理插入到您的Rack中间件堆栈中。 仅当存在RAILS_AUTOSCALE_URL ENV变量时,代理才会与Rails Autoscale通信,该变量在您安装Heroku附加组件时自动发生。 如果RAILS_AUTOSCALE_URL不存在,例如在开发中或...
什么是Rack? Rack是Ruby世界中的一个轻量级、灵活的Web服务器接口规范,它定义了一个统一的标准,使得Ruby Web应用能够与不同的Web服务器无缝集成。Rack简化了Ruby Web应用的部署过程,同时也提供了强大的功能和...
`weixin_rails_middleware` 是基于 Ruby 的 Rack 技术构建的,它能够插入到 Rails 应用的请求处理流程中。当收到微信服务器发来的请求时,中间件会自动处理这些请求,如验证签名、解析XML数据,并提供相应的响应。 ...
同时,它引入了多路由引擎支持,如Rack中间件,使得与其他Web服务器的集成更加容易。此外,ActiveRecord的查询接口(ARel)和ActiveModel的引入增强了模型层的功能和可扩展性。 2. Rails 3.1: 这个版本引入了Asset ...
Obscenity是Ruby / Rubinius,Rails(通过ActiveModel)和Rack中间件的亵渎性过滤器。 安装 将此行添加到您的应用程序的Gemfile中: gem 'obscenity' 然后执行: bundle install 或将其自己安装为: gem ...
rack-perftools_profiler, 使用 perftools.rb 配置 rack 兼容应用程序的中间件 Rack::PerftoolsProfiler使用 perftools.rb 配置机架兼容应用的中间件快速启动假定应用程序使用 Rails 3 ( 你已经在下一节中安装了需求...
9. **Rate Limiting**:防止恶意用户或脚本滥用API,Rails API可以通过中间件(如Rack::Attack)实现请求速率限制。 10. **测试**:测试是API开发的关键部分,Rails API支持RSpec、Minitest等多种测试框架,方便...
Rails中间件负责应用中各个层次的请求处理逻辑。书中介绍了如何查看和定制中间件,以及如何构建自定义的中间件,这部分内容对于理解Rails应用的运行机制以及请求处理流程至关重要。 Rails中的安全性也是本书的重要...
Rack :: BearerAuth是在Rack应用中使用承载身份验证的中间件。 安装 将此行添加到您的应用程序的Gemfile中: gem 'rack-bearer_auth' 然后执行: $ bundle 或将其自己安装为: $ gem install rack-bearer_auth ...
机架式CAS Rack-CAS是执行客户端身份验证的简单中间件。特征基于机架独立于框架的框架适用于,但不依赖于Rails,Sinatra等。 最小的依赖项当前的gem依赖项是 ,和 。 支持CAS额外属性额外属性虽然一团糟。 因此,请...