Skip to main content
32 votes

error 500: Premature end of script headers: index.php

@mcaleaa answer helped me on an acquia based site. To fix it I commented out the following lines in development.services.yml. parameters: http.response.debug_cacheability_headers: true
awm's user avatar
  • 2,469
18 votes

How to check if the current page is a 404 error from a module/template?

Drupal 8.2.x: Unfortunately, drupal_get_http_header("status") doesn't work any more. Try: $status = \Drupal::requestStack()->getCurrentRequest()->attributes->get('exception'); if ($status &...
Gervase's user avatar
  • 281
8 votes
Accepted

Returning alternate HTTP codes for unpublished node

You can try to do this earlier in an exception instead of a response subscriber. Extend HttpExceptionSubscriberBase, so you need less code to do this. Then replace the 403 with a 404 exception with ...
4uk4's user avatar
  • 100k
8 votes

error 500: Premature end of script headers: index.php

In case this helps anyone: I encountered this error on my local site's front page, just after following the instructions here https://www.drupal.org/node/2598914 (Disable Drupal 8 caching during ...
mcaleaa's user avatar
  • 497
7 votes
Accepted

How to issue 404 from a KernelEvents::REQUEST event

You can set a response early in a request event: public function my404Check(RequestEvent $event) { // only return a response for a master request if (!$event->isMainRequest()) { ...
4uk4's user avatar
  • 100k
5 votes
Accepted

error 500: Premature end of script headers: index.php

This is not "solve it all" answer, but it may help those who use Acquia. The problem went away after switching from Fast CGI (mod_fcgid) to Apache module (mod_php) in Acquia DevDesktop->Preferences->...
Nookeen's user avatar
  • 166
5 votes

Alter Header Status Response to 410

Yes, definitely higher up. When you are already inside of a 404 subrequest it is too late. You could put the code in on404() of an HttpExceptionSubscriber, check the path and then replace the 404 with ...
4uk4's user avatar
  • 100k
5 votes
Accepted

How to return Service Worker with custom HTTP header from custom module

To provide a dynamic file, you need to make a Controller with a method like: public function serve(Request $request) { $file_str = $file_system->realpath($module_handler->getModule('...
rémy's user avatar
  • 5,720
4 votes

Hide title if 404 error

I don't think you need a custom module for something like this... This should be as easy as: Go to Configuration -> System -> Basic Site Settings, get the page URL you have for the 404 page. Go ...
cchen's user avatar
  • 757
3 votes

How to handle the cache per user in REST Resource?

@Leigh is right and user does exist. Cache contexts are hierarchical (see change record https://www.drupal.org/node/2451661) and user is a top level context. So this should work (note the plural form ...
4uk4's user avatar
  • 100k
3 votes
Accepted

How do I return 500 for fatal errors?

This is a known issue, whose fix didn't make it into the Drupal 7 core so far. The culprit can be found within the _drupal_exception_handler(). If another error occurs while handling an exception, it ...
Mario Steinitz's user avatar
3 votes

Handling access denied result

Generally, the correct way is to throw new AccessDeniedHttpException() over setting a 403 or a redirect response, which bypasses the exception handling, so that it's no longer possible to configure a ...
4uk4's user avatar
  • 100k
3 votes
Accepted

8 - Alter HTTP Response Headers

Got it! From these two sources: How to embed drupal content in other sites (remove X-Frame-Options: SAMEORIGIN)? https://wunderkraut.se/blogg/remove-xframe-options-and-set-contentsecuritypolicy I ...
Raphael Rafatpanah's user avatar
3 votes

What should I set my Content-Security-Policy to?

The policy needs to contain every domain where assets are loaded from, which will vary depending on which services your site uses such as a CDN or third party JavaScript widgets. For Google Analytics,...
gapple's user avatar
  • 1,564
3 votes

Guzzle httpClient Drupal Core throwing cURL error 28 Operation timed out

As @cilefen suggested in his comments my problem was related to the timeout value that was being set in the calling code rather then an error with an undefined constant. I had fixed the error in my ...
Hershy's user avatar
  • 191
3 votes
Accepted

$current_user->id() returns 0 when logged in for HTTP Middleware

User authentication does not happen in a middleware, it's in the request event subscriber AuthenticationSubscriber with priority 300: public static function getSubscribedEvents() { // The ...
4uk4's user avatar
  • 100k
2 votes
Accepted

Need to alter response headers for error pages

You could use a template_preprocess_maintenance_page() invocation in your theme's template.php so that when you go to maintenance mode (or the DB is down) it will trigger your needed status code: ...
Shawn Conn's user avatar
  • 26.9k
2 votes

HTTP error 500 when backup entire site

This is your error: General error: 2006 MySQL server has gone away You can try to fix this in two ways: my.ini Open your my.ini file and locate max_allowed_packet. By default this is 1M. Setting ...
Wim Mostrey's user avatar
  • 2,827
2 votes

Problem with SSL certificate

There are some known issues with Drupal 7.x in some server configurations particularly around PHP 5.6 and OpenSSL 0.9x due to changes in how PHP verifies SSL certificates. Acquia has some notes about ...
acrosman's user avatar
  • 2,728
2 votes
Accepted

How do I pass parameters as JSON format to the HTTP client request?

You can add it to the request like so: use Drupal\Component\Serialization\Json; ... $response = $client->get($url, [ 'headers' => ['Accept' => 'text/plain'], 'json' => Json::...
Clive's user avatar
  • 167k
2 votes
Accepted

How to get and apply current page query parameters from current AJAX request

No, HTTP_REFERER is not reliable and yes, the solution is to add the query parameters of the current request to each AJAX link. Form API does the same for form elements: RenderElement::...
4uk4's user avatar
  • 100k
2 votes
Accepted

How to add certificate to drupal_http_request()?

You need to supply a context parameter in the options for drupal_http_request. The value is a stream context created using the PHP function stream_context_create. There are a lot of possible ...
Alfred Armstrong's user avatar
2 votes
Accepted

How do I handle an incoming POST request in a module?

If posting to external URLs is allowed, and given that you are not familiar with Drupal, you can post that data to an external URL where you can write a script using the language / framework you are ...
anoopjohn's user avatar
  • 938
2 votes

How to get the uncached version of request headers?

Concerning CDNs or Varnish you need to ask in a different place. In Drupal you find two caches for requests/responses: The Internal Page Cache, which is implemented in a kernel middleware, and you ...
4uk4's user avatar
  • 100k
2 votes

Hide title if 404 error

This should work: /** * Implements hook_preprocess_HOOK(). */ function modulename_preprocess_html(&$variables) { $status = \Drupal::requestStack()->getCurrentRequest()->attributes->...
Stefan Korn's user avatar
  • 1,211
2 votes
Accepted

How to force a JS library to be loaded via HTTPS?

That's a protocol relative include, meaning it will take the current protocol and use that. If you access via http, that's what you would get. Is the site being tested under https? Is something ...
Kevin's user avatar
  • 27.9k
2 votes
Accepted

Making an HTTP subrequest causes CurrentRouteMatch to have the wrong route

After running the subrequest the request stack is quite a mess, it still contains the subrequest while the route match stack was cleaned up. If you then get the current route match this will return a ...
4uk4's user avatar
  • 100k
2 votes

How to pass and receive an http request body in GET?

I don't know if this is allowed by spec, see the comment from @Hudri and https://stackoverflow.com/questions/978061/http-get-with-request-body, but it works. When adding a body in a Guzzle GET request ...
4uk4's user avatar
  • 100k
2 votes
Accepted

Sub request doesn't take care of the language

I was a bit overly optimistic in the previous question suggesting a sub-request. The language manager service doesn't store data in such a way that it can run within a sub-request scope. So it seems ...
4uk4's user avatar
  • 100k

Only top scored, non community-wiki answers of a minimum length are eligible