Skip to content

Instantly share code, notes, and snippets.

@alibo
Created February 14, 2016 19:17
Show Gist options
  • Save alibo/b5c9a650f580e9f879fd to your computer and use it in GitHub Desktop.
Save alibo/b5c9a650f580e9f879fd to your computer and use it in GitHub Desktop.
A simple solution for using Laravel's rate-limiting on openshift.com
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Routing\Middleware\ThrottleRequests;
class OpenshiftThrottleRequests extends ThrottleRequests
{
/**
* Resolve request signature.
*
* @param \Illuminate\Http\Request $request
* @return string
*/
protected function resolveRequestSignature($request)
{
if (! $request->route()) {
throw new RuntimeException('Unable to generate fingerprint. Route unavailable.');
}
return sha1(
implode('|', $request->route()->methods()).
'|'.$request->route()->domain().
'|'.$request->route()->uri().
'|'.$request->header('x-forwarded-for', $request->ip())
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment