laravel / lumen-framework

The Laravel Lumen Framework.
https://lumen.laravel.com
MIT License
1.47k stars 419 forks source link

http response status code always return 200 #1007

Closed zhengyuhe123 closed 4 years ago

zhengyuhe123 commented 4 years ago

Description:

I installed lumen by composer global require "laravel/lumen-installer"

add the code in reoutes/web.php file $router->get('/', function () use ($router) { return response()->json(['test' => 1], 500); });

I think http response status code will return 500 but always return 200 image

I tested a nonexistent url http response still returns code 200 image

Please tell me how to set the http status code, thanks

Steps To Reproduce:

edit code in routes/web.php $router->get('/', function () use ($router) { return response()->json(['test' => 1], 500); });

driesvints commented 4 years ago

Hi there,

Thanks for reporting but it looks like this is a question which can be asked on a support channel. Please only use this issue tracker for reporting bugs with the library itself. If you have a question on how to use functionality provided by this repo you can try one of the following channels:

However, this issue will not be locked and everyone is still free to discuss solutions to your problem!

Thanks.

dericlima commented 4 years ago

I had the same issue on my app (Lumen 6.4) and believe me or not the issue was a extra blank line at the top of my app.php.


<?php
require_once __DIR__.'/helpers.php';
require_once __DIR__.'/../vendor/autoload.php';

So I just removed it:

<?php
require_once __DIR__.'/helpers.php';
require_once __DIR__.'/../vendor/autoload.php';

And everything was working like a charm!!

sharaf84 commented 4 years ago

@dericlima Thanks, in my case, the extra blank line was in the routes/web.php

marvix commented 4 years ago

How did you catch this empty error?

abdelaliabouelhassan commented 1 month ago

@sharaf84 thank you, I had the same issue I found that I have an extra space in the routes/web.php