I’m trying to create a custom API endpoint that responds with plain text. No matter what I do, the response always gets returned as HTML. As an experiment, I also tried a JSON response, and it had the same issue.
Here’s a simplified example to demonstrate the problem. I create a terminal page at /xwiki/bin/view/api/test with the following content:
{{velocity}}
#if ($stringtool.contains("$!request.getRequestURL()", "/get/"))
#set ($discard = $response.setContentType('text/plain'))
#set ($name = "$!request.name")
Hello, $name
#end
{{/velocity}}
If I call this endpoint with:
https://www.example.com/xwiki/bin/get/api/test?name=Rob
the response looks like this:
<p>Hello, Rob</p>
For more complex responses with multiple lines, I get a <br>
inserted between each line.
I get the same output whether I go through the browser (Chrome/Brave) or via the command line using curl.
What do I need to do to force a plain text response of:
Hello, Rob
If it matters, I’m running XWiki behind an Apache reverse proxy with the following settings:
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPreserveHost On
ProxyPass /xwiki http://localhost:8080/xwiki nocanon
ProxyPassReverse /xwiki http://localhost:8080/xwiki
6 posts - 2 participants