Problem/Motivation

drupal_add_http_header() has been deprecated in drupal 8. It provided the functionality to add a header to the response sent for a request. The alternate method that has been specified in the change record https://www.drupal.org/node/2181523 is is to add headers to the response object but it assumes that the response object has been created and is accessible. This restricts most of the functionality of this API.

Proposed resolution

There should be an alternative way to specify headers in the request object and the route object so that they get added to the final respone when it is created

Remaining tasks

User interface changes

API changes

Comments

dawehner’s picture

drupal_add_http_header() has been deprecated in drupal 8. It provided the functionality to add a header to the response sent for a request. The alternate method that has been specified in the change record https://www.drupal.org/node/2181523 is is to add headers to the response object but it assumes that the response object has been created and is accessible. This restricts most of the functionality of this API.

You should rather try to refactor your code and change it not in the middle of nowhere.

dawehner’s picture

Status: Active » Fixed

I would argue that this is the design of Drupal 8.

shivanshuag’s picture

Status: Fixed » Active

@dawehner Let me describe my use case. I am porting the module securesite - (http://drupal.org/projects/securesite) to d8. The module provides HTTP Digest Authentication to enter the site. For this, I need to catch a request thorugh event subscriber and ask for credentials. When the user has sent the credentials and they are correct, I need to send a header - Authentication Info - to the client containing some details for the authentication. In the event subscriber, the response object has yet not been created (and I cannot create a new response object as the response content is yet to be prepared).

Please help me if there is another way to provide this functionality. I am still a noob in drupal but from what I have researched, I could not find a way to do this.

shivanshuag’s picture

berdir’s picture

Another example for adding HTML headers from anywhere are things like og: and other metatags which can happen through a rendered entity or a block. We need a way to specify this through #attached or something.

ianthomas_uk’s picture

There's lots of good discussion about this on #2184907: Remove uses of drupal_add_http_header and related functions, particularly #10-19.

dawehner’s picture

Status: Active » Fixed

Either you can use #attachment['http_header'] or better manipulate the HTTP response directly.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.