forked from ushahidi/platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(http): add content-length header to responses
- Loading branch information
Showing
4 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Ushahidi\App\Http\Middleware; | ||
|
||
use Closure; | ||
|
||
class AddContentLength | ||
{ | ||
/** | ||
* Add content-length header to responses before being sent. | ||
* This only happens if it hasn't been already set. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param \Closure $next | ||
* @return mixed | ||
*/ | ||
public function handle($request, Closure $next) | ||
{ | ||
$response = $next($request); | ||
|
||
if (!$response->isEmpty() && !$response->headers->get('Content-Length')) { | ||
$response->headers->set( | ||
'Content-Length', | ||
// ensure that we get byte count by using 8bit encoding | ||
mb_strlen($response->getContent(), '8bit') | ||
); | ||
} | ||
return $response->prepare($request); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters