Adding header link on https response

Hello

i have 2 pages with two URL variation

URL 1 : http://localhost/index.php/journalID/article/view/57886

where it seems controlled by

function view($args, $request) {
       $context = $request->getContext();
       $user = $request->getUser();
       $issue = $this->issue;
       $article = $this->article;
       $publication = $this->publication;
       $templateMgr = TemplateManager::getManager($request);
       $templateMgr->assign(array(
          'issue' => $issue,
          'article' => $article,
          'publication' => $publication,
          'firstPublication' => reset($article->getData('publications')),
          'currentPublication' => $article->getCurrentPublication(),
          'galley' => $this->galley,
          'fileId' => $this->fileId,
       ));
       $this->setupTemplate($request);
  
       $sectionDao = DAORegistry::getDAO('SectionDAO'); /* @var $sectionDao SectionDAO */
       $templateMgr->assign([
          'ccLicenseBadge' => Application::get()->getCCLicenseBadge($publication->getData('licenseUrl')),
          'publication' => $publication,
          'section' => $sectionDao->getById($publication->getData('sectionId')),
       ]);
  
       if ($this->galley && !$this->userCanViewGalley($request, $article->getId(), $this->galley->getId())) {
          fatalError('Cannot view galley.');
       }
  
       $categoryDao = DAORegistry::getDAO('CategoryDAO'); /* @var $categoryDao CategoryDAO */
       $templateMgr->assign([
          'categories' =>   $categoryDao->getByPublicationId($publication->getId())->toArray()
       ]);

Full code at https://pkp.sfu.ca/ojs/doxygen/master/html/ArticleHandler_8inc_8php_source.html
and
URL 2: http://localhost/index.php/journalID/article/download/57886/123

the header status seems controlled by this code

		// Stream the file to the end user.
		$mimetype = $file->mimetype ?? $this->fs->getMimetype($path) ?? 'application/octet-stream';
		$filesize = $this->fs->getSize($path);

		header("Content-Type: $mimetype");
		header("Content-Length: $filesize");
		header('Accept-Ranges: none');
		header('Content-Disposition: ' . ($inline ? 'inline' : 'attachment') . "; filename=\"$filename\"");
		header('Cache-Control: private'); // Workarounds for IE weirdness
		header('Pragma: public');

		fpassthru($this->fs->readStream($path));
		exit();
	}

full code is at https://pastebin.com/hWQVY7jz

57886 is article ID and 123 is fileID

I want to add an extra header from URL 2 pointing back to URL 1, something like
header('link: <https://URL 1>; rel="canonical"');

so the header response from URL 2 as follow

GET: http://localhost/index.php/journalID/article/download/57886/123
Status: 200 OK
Version: HTTP/1.1
Transferred: 628 B (371.87 KB size)
Referrer Policystrict-origin-when-cross-origin
Request PriorityHighest

RESPONSE HEADER

HTTP/1.1 200 OK
Date: Tue, 30 Aug 2022 12:39:34 GMT
Server: Apache/2.4.53 (Win64) OpenSSL/1.1.1n PHP/7.4.29
X-Powered-By: PHP/7.4.29
Set-Cookie: OJSSID=r0irplhhfbmmqegu2jbau38bh7; expires=Thu, 29-Sep-2022 12:39:34 GMT; Max-Age=2592000; path=/ojs3/
link: <https://localhost/index.php/journalID/article/view/57886>; rel="canonical"
Content-Length: 380797
Accept-Ranges: none
Content-Disposition: attachment; filename="-20180107.pdf"
Cache-Control: private
Pragma: public
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: application/pdf

I tried with this piece of code but its only printing current URL which not what I wanted to

header('link: <https://localhost'.$_SERVER['REQUEST_URI'].'>; rel="canonical"');

can someone help me how do I set link header on URL 2 back to URL 1?
link: <https://[URL1](http://localhost/index.php/journalID/article/view/57886)>; rel="canonical"
thank you

Sponsor our Newsletter | Privacy Policy | Terms of Service