Headers not set in VM 3.0.10-12 Worked in VM 3.0.9 With proposed solution

Started by welrachid, December 02, 2015, 11:03:22 AM

Previous topic - Next topic

welrachid

Joomla 3.4.5

components/com_virtuemart/controllers/plugin.php Line: 72 + 76

jExit();

makes the joomla exit with outputted data. This means no headers are set before output.

Im using example with parameters format=json
Best regards,
Wel

welrachid

Best regards,
Wel

Milbo

So what do you suggest? We used jExit instead of die. So how do we sent the header?
should we use someting like
$this->app->mimeType = 'application/json';
??
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

welrachid

Hi Milbo
Sry for the late reply. Im not sure why im not being notified for new entries in my thread. anyway - ill make sure ill check up a couple of times during day

Im not that much into the Joomla platform, but from what i can read around the web the problem that occours is that joomla exists without sending the headers. so the solution is to send the headers yourself.
Doing that lead me to an other problem. The mimetype was not printed either. so i have to manually set the content-type header
See my working code:
         if ($format == 'json') {
            $document->setMimeEncoding ('application/json');
            // Change the suggested filename.
            JResponse::setHeader ('Content-Disposition', 'attachment;filename="' . $type . '.json"');
            JResponse::setHeader("Content-type","application/json");
            JResponse::sendHeaders();
            echo json_encode ($render);
            jExit();
         }

reading the platform api says that this method is deprecated:
https://api.joomla.org/cms-3/classes/JResponse.html#method_sendHeaders

They write that we should :
4.0 Use JApplicationWeb::sendHeaders() instead

However when i write that in that place the JApplicationWeb is not defined or instantiated or something..it fails.. but again i think the whole JResponse class will be deprecated and replaced by JApplicationWeb - so when VM is updated at some point in the future this will be handled by the new class i guess?

Again.. i dont know "much" about what happens in the core of VM, so i cannot say if everything is being dealt with with my code. but please feel free to change it the way you want and let me know if i can be of any assistance.

Have a great friday
Best regards,
Wel

welrachid

perhaps someone from the development team can confirm this bug and tell me if the proposed fix is good enough, so i can go ahead and upgrade production på newest versions and make those hack (that will be overwritten once u release the next version)
Best regards,
Wel

Milbo

oh sorry, I thought I answered you already. Yes your fix is quite adequate. I added almost the same now. You may check the svn at http://dev.virtuemart.net/projects/virtuemart/repository
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

welrachid

Best regards,
Wel