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

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

问题描述

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 服务器.

Rack as Design

Rack middleware is more than "a way to filter a request and response" - it's an implementation of the pipeline design pattern for web servers using Rack.

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

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 演化而来, 上有一个很好的介绍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.

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

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