Skip to content
Advertisement

LARAVEL – Customize response headers when using rate limiting middleware

I am developing a project in laravel8 (which is still new) and I want to hide some custom response headers(starting with x-) like:

JavaScript

enter image description here

I want to customize this behavior and hide these headers, how can I easily find code (in a framework), which set’s these headers

My code:

JavaScript

Advertisement

Answer

Let’s say we can create a new AppHttpMiddlewareThrottleRequests class which will extend original IlluminateRoutingMiddlewareThrottleRequests. And override the method getHeaders to your own that will return empty array.

JavaScript

And then all you need to do is to change middleware definitions inside app/Http/Kernel.php file. Property $routeMiddleware where you register ‘throttle’ middleware IlluminateRoutingMiddlewareThrottleRequests::class you can change to your own implementation AppHttpMiddlewareThrottleRequests::class.

In my case it is:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement