We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33992 ☆ A M B ☆
    • 455 Posts
    To add dynamic headers based on current source code
    Revo>=2/core/model/modx/modxresponse.class.php::outputContent()
    Create a plugin on OnWebPagePrerender event (or similar which $modx->resource has value) and you can access to current custom headers via
    $modx->resource->getOne('ContentType')->get('headers')

    Result is indexed array of string header rows. You could update it for current response without saving.
    Sample:
    $contentType = $modx->resource->getOne('ContentType');
    $headers = $contentType->get('headers');
    
    if ($case_1) {
        $headers[] = "X-Custum1: 1";
        $headers[] = "X-Custum2: 2";
    } else if ($case_2) {
        $headers = array("X-Custum3: 3"); // Replace
    } else if ($case_3) {
        $headers = array(); // Remove all
    }
    
    $contentType->set('headers', $headers);

    Avoid calling $contentType->save(); at the end! unless you know what you're doing...

    P.s.
    Adding fixed custom HTTP headers is possible in Manager>Content Types section.
      God loves me. 【ツ】


      MODX.ir (Persian Support)

      Boplo.ir/modx/ (Persian)