GatewayFilters المضمّنة التي ينبغي معرفتها
استكشفوا مصانع GatewayFilter الجاهزة الأكثر فائدة، لتحلّوا المهام الشائعة دون كتابة تعليمات برمجية مخصصة.
GatewayFilters المضمّنة التي ينبغي معرفتها درس مجاني في API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Filters You Get for Free
Before writing custom filters, know that Spring Cloud Gateway ships with dozens of ready-made GatewayFilter factories. You attach them per route in configuration.
This lesson tours the ones you will reach for most often.
AddRequestHeader
AddRequestHeader injects a header into every request before it reaches the backend, useful for tagging traffic from the gateway.
filters:
- AddRequestHeader=X-Source, gatewayAddResponseHeader
Likewise, AddResponseHeader adds a header to the response sent back to the client, for example a marker showing which gateway handled it.
filters:
- AddResponseHeader=X-Handled-By, edge-gatewayRewritePath
RewritePath uses a regex to transform the incoming path before forwarding. Strip a public prefix while keeping the rest.
filters:
- RewritePath=/api/(?<seg>.*), /$\{seg}StripPrefix
When you just need to drop leading path segments, StripPrefix is simpler than a rewrite. StripPrefix=1 removes the first segment.
filters:
- StripPrefix=1
# /service/users -> /usersPrefixPath
The reverse of stripping, PrefixPath prepends a segment to the path sent upstream.
filters:
- PrefixPath=/internal
# /users -> /internal/usersSetStatus
SetStatus forces the HTTP status code of the response, handy for maintenance routes or deprecation notices.
filters:
- SetStatus=410RedirectTo
RedirectTo returns a redirect response with a status and target URL instead of proxying.
filters:
- RedirectTo=302, https://new.example.comRemoveRequestHeader
Strip a header before it reaches the backend with RemoveRequestHeader, for example to drop a client-supplied header you do not trust.
filters:
- RemoveRequestHeader=CookieA Full Route Example
Filters stack in declared order. Here a route strips a prefix, tags the request, and marks the response.
routes:
- id: users
uri: http://users-svc:8080
predicates:
- Path=/api/users/**
filters:
- StripPrefix=2
- AddRequestHeader=X-Source, gateway
- AddResponseHeader=X-Handled-By, edgeDefault Filters
Use default-filters to apply a filter to every route at once, such as adding a correlation header everywhere.
spring:
cloud:
gateway:
default-filters:
- AddResponseHeader=X-Gateway, trueQuick Check
You want to turn /api/users into /users by dropping the first path segment. Which filter is the simplest fit?
Recap
You now have a toolbox of built-in filters:
- Header filters: Add/Remove request and response headers
- Path filters: StripPrefix, PrefixPath, RewritePath
- Response control: SetStatus, RedirectTo
default-filtersapply globally
Reach for these before writing custom code, then build custom filters only when nothing fits.
الأسئلة الشائعة
هل درس «GatewayFilters المضمّنة التي ينبغي معرفتها» مجاني؟
نعم — نص درس «GatewayFilters المضمّنة التي ينبغي معرفتها» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)، انتقل إلى CoddyKit PRO. تتضمن دورة API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 4 دروس في المجموع.
ماذا ستتعلم في «GatewayFilters المضمّنة التي ينبغي معرفتها»؟
استكشفوا مصانع GatewayFilter الجاهزة الأكثر فائدة، لتحلّوا المهام الشائعة دون كتابة تعليمات برمجية مخصصة. تتمرن على API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)؟
لا تُشترط خبرة سابقة. API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «GatewayFilters المضمّنة التي ينبغي معرفتها»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) هذا؟
نعم. كل درس في API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- المرشحات العامة وGatewayFilterFactory
- مرشحات الطلبات والاستجابات المخصّصة
- المعالجة المسبقة واللاحقة باستخدام المرشحات
- GatewayFilters المضمّنة التي ينبغي معرفتها