什么是Rack中间件? [英] What is Rack middleware?

查看:111
本文介绍了什么是Rack中间件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ruby中的Rack中间件是什么?我找不到任何关于中间件意思的好解释。

What is Rack middleware in Ruby? I couldn't find any good explanation for what they mean by "middleware".

推荐答案

Rack as Design



机架中间件不仅仅是过滤请求和响应的一种方式 - 它是 Rack的Web服务器的ParallelPatterns / PatternLanguage / AlgorithmStructure / Pipeline.htmrel =noreferrer>管道设计模式

它非常清晰地分离出处理请求的不同阶段 - 关注点分离是所有精心设计的软件产品的关键目标。

It very cleanly separates out the different stages of processing a request - separation of concerns being a key goal of all well designed software products.

例如,对于Rack,我可以有不同的管道阶段:

For example with Rack I can have separate stages of the pipeline doing:


  • 认证:当请求到达时,用户登录详细信息是否正确?如何验证此OAuth,HTTP基本身份验证,名称/密码?

  • Authentication: when the request arrives, are the users logon details correct? How do I validate this OAuth, HTTP Basic Authentication, name/password?

授权:是授权执行此操作的用户特别的任务?,即基于角色的安全性。

Authorisation: "is the user authorised to perform this particular task?", i.e. role-based security.

缓存:我已经处理过这个请求,我可以返回一个缓存吗?结果?

Caching: have I processed this request already, can I return a cached result?

装修:如何增强下游处理效果的请求?

Decoration: how can I enhance the request to make downstream processing better?

性能&使用情况监控:我可以从请求和响应中获得哪些统计信息?

Performance & Usage Monitoring: what stats can I get from the request and response?

执行:实际处理请求和提供回复。

Execution: actually handle the request and provide a response.

能够分开不同阶段(并可选择包括它们)对开发有很大帮助结构良好的应用程序。

Being able to separate the different stages (and optionally include them) is a great help in developing well structured applications.

还有一个围绕机架中间件开发的优秀生态系统 - 你应该是能够找到预先构建的机架组件来执行上述所有步骤以及更多步骤。有关中间件列表,请参见 Rack GitHub wiki

There's also a great eco-system developing around Rack Middleware - you should be able to find pre-built rack components to do all of the steps above and more. See the Rack GitHub wiki for a list of middleware.

中间件是一个可怕的术语,指的是任何协助但不直接参与的软件组件/库在执行某项任务时。非常常见的示例是日志记录,身份验证和其他常见的水平处理组件。这些往往是每个人在多个应用程序中需要的东西,但没有太多人对构建自己感兴趣(或应该)。

Middleware is a dreadful term which refers to any software component/library which assists with but is not directly involved in the execution of some task. Very common examples are logging, authentication and the other common, horizontal processing components. These tend to be the things that everyone needs across multiple applications but not too many people are interested (or should be) in building themselves.

机架中间件是从Rack发展而来的,机架中间件简介

Rack middleware evolved out of Rack and there is a great intro at Introduction to Rack middleware.

维基百科上有一个中间件介绍这里

There's an intro to middleware on Wikipedia here.

这篇关于什么是Rack中间件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆