XF 2.0 Is it possible to extend XF\Http

AndyB

Well-known member
I would like to create a XF2 version of an add-on called Open PDF which will open an attached PDF document instead of downloading it, I need to add the following line of code to this file:

XF\Http\Response.php

1516814394002.webp

Is it possible to extend the XF\Http and specifically this protected item?

Thank you.
 
\XF\Http\Response is not dynamically loaded (with extendClass), so you can't extend the class.

That variable is referenced in this function:

Code:
    public function setAttachmentFileParams($fileName, $extension = null)
    {
        if ($extension === null)
        {
            $extension = pathinfo($fileName, PATHINFO_EXTENSION);
        }

        $extension = strtolower($extension);

        if ($extension && isset($this->inlineDisplaySafeTypes[$extension]))
        {
            $this->contentType($this->inlineDisplaySafeTypes[$extension], '')
                ->setDownloadFileName($fileName, true);
        }
        else
        {
            $this->contentType('application/octet-stream', '')
                ->setDownloadFileName($fileName);
        }

        return $this;
    }

So you could perhaps just use the relevant part of the code, contentType and setDownloadFileName are public functions, and simply bypass this method.

Something like:
Code:
$response->contentType('application/pdf', '')->setDownloadFileName($fileName), true)
 
Top Bottom