# 自定义过滤器

Spring Cloud Gateway允许我们通过在网关中使用过滤器来构建自定义逻辑。

Spring Cloud Gateway支持以下两种类型的过滤器：

* **预过滤器：**&#x5728;实际请求发送到目标目的地之前调用预过滤器。预过滤器通常执行预处理任务，例如确保服务具有一致的消息格式（例如，关键的HTTP头已设置）或充当门卫以确保调用服务的用户已经进行了身份验证（他们确实是他们所声称的用户）。
* **后过滤器：**&#x5728;目标服务处理请求并将响应发送回客户端后调用后过滤器。通常，我们会实现后过滤器以记录来自目标服务的响应，处理错误或审计响应以获取敏感信息。

> ## <mark style="color:orange;">需要注意的是，预过滤器无法将用户重定向到不同的端点或服务。</mark>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bohans.gitbook.io/ji-chu/spring/group-1/spring-cloud/wang-guan-spring-cloud-gateway/spring-cloud-gateway/wei-ci-he-guolqi-gong-chang/zi-ding-yi-guolqi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
