<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Oct 9, 2014 at 1:47 PM, Andrew Beverley <span dir="ltr"><<a href="mailto:andy@andybev.com" target="_blank">andy@andybev.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi guys,<br></blockquote><div><br></div><div>Hi Andrew. :)</div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
I apologise in advance that this is rather vague, but I'm hoping that<br>
someone might be able to point me in the right direction of where I<br>
should be looking.<br></blockquote><div><br></div><div>Not at all! That is an excellent question.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>[...] so I won't go into the details here, but I wondered whether<br>
someone can point me to the relevant parts of the Dancer2 code that I<br>
should start poking around in (in particular the code which detects<br>
whether to serialize the data).</blockquote><div><br></div><div><br></div><div>You can see that Dancer2::Core::Request checks for a supported content type. The line is:</div><div><div><br></div><div>    return unless $self->serializer->support_content_type($content_type);</div></div><div><br></div><div>However, in Dancer2::Core::Response, it doesn't check for a supported content type in the request in order to serialize a response back. This would be the correct behavior since a serializer basically says "I would like to serialize my responses" and not "I would like to serialize my responses IF the request was made with a header". The reason it ignores any request header in the response is because it is, by definition, a *request* header. This means it only relates to the request, not the response.</div><div><br></div><div>If you would like to return HTML and serialized information, you have two options:</div><div>1. Separate the code that accepts and returns serialized data into two different Dancer2 apps.</div><div>2. Don't use a serializer, and call the to_json and from_json when *you* decide it's the right time for it.</div><div><br></div><div>I hope this answer helps.</div></div></div></div>