Skip to content

Commit 8aa36bc

Browse files
authored
Merge pull request dingo#1102 from lucasmichot/feature/master/etag-sha
Use sha1 to avoid collisions
2 parents 5a84472 + aed52fc commit 8aa36bc

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

src/Http/RateLimit/Handler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function rateLimitRequest(Request $request, $limit = 0, $expires = 0)
103103
} elseif ($limit > 0 || $expires > 0) {
104104
$this->throttle = new Route(['limit' => $limit, 'expires' => $expires]);
105105

106-
$this->keyPrefix = md5($request->path());
106+
$this->keyPrefix = sha1($request->path());
107107

108108
// Otherwise we'll use the throttle that gives the consumer the largest
109109
// amount of requests. If no matching throttle is found then rate

src/Routing/Router.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ protected function prepareResponse($response, Request $request, $format)
622622

623623
if ($response->isSuccessful() && $this->requestIsConditional()) {
624624
if (! $response->headers->has('ETag')) {
625-
$response->setEtag(md5($response->getContent()));
625+
$response->setEtag(sha1($response->getContent()));
626626
}
627627

628628
$response->isNotModified($request);

tests/Routing/RouterTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,18 +173,18 @@ public function testRouterPreparesNotModifiedResponse()
173173
$response = $this->router->dispatch($request);
174174

175175
$this->assertSame(200, $response->getStatusCode());
176-
$this->assertSame('"'.md5('bar').'"', $response->getETag());
176+
$this->assertSame('"'.sha1('bar').'"', $response->getETag());
177177
$this->assertSame('bar', $response->getContent());
178178

179179
$request = $this->createRequest('foo', 'GET', [
180-
'if-none-match' => '"'.md5('bar').'"',
180+
'if-none-match' => '"'.sha1('bar').'"',
181181
'accept' => 'application/vnd.api.v1+json',
182182
]);
183183

184184
$response = $this->router->dispatch($request);
185185

186186
$this->assertSame(304, $response->getStatusCode());
187-
$this->assertSame('"'.md5('bar').'"', $response->getETag());
187+
$this->assertSame('"'.sha1('bar').'"', $response->getETag());
188188
$this->assertEmpty($response->getContent());
189189

190190
$request = $this->createRequest('foo', 'GET', [
@@ -195,7 +195,7 @@ public function testRouterPreparesNotModifiedResponse()
195195
$response = $this->router->dispatch($request);
196196

197197
$this->assertSame(200, $response->getStatusCode());
198-
$this->assertSame('"'.md5('bar').'"', $response->getETag());
198+
$this->assertSame('"'.sha1('bar').'"', $response->getETag());
199199
$this->assertSame('bar', $response->getContent());
200200
}
201201

0 commit comments

Comments
 (0)