Support the ongoing development of Laravel.io →
Configuration Requests
Last updated 2 years ago.
0

I am assuming that the Response::make call is in a controller method.

Can you post the entire controller method and route definition that calls it?

0

Hi there

Option 1.

Route::get('test' , function(){
    return \Response::make('message', 400);
});

Option 2.

Route::get('test', 'TestController@index');

// The controller
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class TestController extends Controller
{
/**
 * Display a listing of the resource.
 *
 * @return Response
 */
public function index()
{
    return \Response::make('message', 400);
}

/**
 * Show the form for creating a new resource.
 *
 * @return Response
 */
public function create()
{
    //
}

/**
 * Store a newly created resource in storage.
 *
 * @return Response
 */
public function store()
{
    //
}

/**
 * Display the specified resource.
 *
 * @param  int  $id
 * @return Response
 */
public function show($id)
{
    //
}

/**
 * Show the form for editing the specified resource.
 *
 * @param  int  $id
 * @return Response
 */
public function edit($id)
{
    //
}

/**
 * Update the specified resource in storage.
 *
 * @param  int  $id
 * @return Response
 */
public function update($id)
{
    //
}

/**
 * Remove the specified resource from storage.
 *
 * @param  int  $id
 * @return Response
 */
public function destroy($id)
{
    //
}

}

the result is always the browser showing "message", however the HTTP header status is "200 OK". This, as mentioned, also is the case for any fatal error. Unknown route for example shows the stack trace, but the header is again 200.

Last updated 9 years ago.
0

Tried Option 1. in a fresh laravel install and as expected I am getting a 400 response.

Only thing that comes to mind is middleware. Since you're not registering any middleware specifically for this route (I am assuming that your Route::get call is not wrapped in a Route::group). I would take a look at your Http/Kernel's $middleware array (not $routeMiddleware).

If nothing there is causing this, I would try to step through the code in a debugger to see where the status is coming from.

Last updated 9 years ago.
0

I have reverted that file to it's original state, same issue. The route is not wrapped in any group, or middleware. The routes should be accessed as normal.

heck, even if I try

return http_response_code(400);

yup, you guessed it. It actually shows 200!

Can you recommend a debugger? I generally just use chrome's inspector, but that obviously just spits out the final header.

I suppose I may also try a fresh Laravel install, but this is killing me.

Again, thanks for you efforts.

Last updated 9 years ago.
0

If I clear out the index.php and place

return http_response_code(500);

I still get a 200. What get's loaded first in laravel? Shouldn't this be the very top of the chain?

Last updated 9 years ago.
0

How are you serving the site? Perhaps your web server is messing with the headers?

0

Hello, seems that this issue is troubling many developpers, I had faced it in one of my web applications, it takes me more that 5 days to find where the problem was. I think that you can fixe it just by changing the encoding format of your file where you want to put the instruction of returning a specific HTTP Status instead of 200. Check the best answer of this topic :

Big Problem : Page Not Found returns HTTP status code 200 instead of 404 laravel 5.1

Last updated 8 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.