<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to set HTTP status in from serverinterface/queryhandlers in FlexSim Forum</title>
    <link>https://forums.autodesk.com/t5/flexsim-forum/how-to-set-http-status-in-from-serverinterface-queryhandlers/m-p/13575369#M74731</link>
    <description>&lt;P&gt;&lt;I&gt;[ FlexSim 24.0.2 ]&lt;/I&gt;&lt;/P&gt;&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;We use custom query handlers in MAIN:/project/exec/globals/serverinterface/queryhandlers to interact with our models via FlexSim Webserver, as documented in  &lt;A id="isPasted" href="https://docs.flexsim.com/en/24.0/Reference/DeveloperAdvancedUser/Webserver/Webserver.html#InstanceQueries"&gt;https://docs.flexsim.com/en/24.0/Reference/DeveloperAdvancedUser/Webserver/Webserver.html#InstanceQueries&lt;/A&gt;&lt;/P&gt;&lt;P&gt;What I noticed is that queryinstance always responds with HTTP status code 200 OK, and there doesn't seem a way to set a different status. In particular I'd like to be able to reply with 400 Bad Request or 404 Not Found.&lt;BR /&gt;&lt;BR /&gt;I noticed than many default queryhandlers use this or similar code:&lt;/P&gt;&lt;PRE&gt;setnodestr(replyNode, "HTTP/1.1 404 Not Found");
return replyNode;&lt;/PRE&gt;&lt;P&gt;However, if I try to do the same and  set replyNode to be the header of the response, it still ends up as the body of the response with a status 200.&lt;/P&gt;&lt;P&gt;For instance, this HTTP request&lt;/P&gt;&lt;P&gt;&lt;A href="http://127.0.0.1:10001/webserver.dll?queryinstance=TestModel&amp;amp;instancenum=1&amp;amp;getnodedata=doesnotexist"&gt;http://127.0.0.1:10001/webserver.dll?queryinstance=TestModel&amp;amp;instancenum=1&amp;amp;getnodedata=doesnotexist&lt;/A&gt;&lt;/P&gt;&lt;P&gt;results in a response with HTTP status code 200 and the body fakes to be an HTTP response:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="1709896897369.png"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1522797i60254D8B64E033F5/image-size/large?v=v2&amp;amp;px=999" role="button" title="1709896897369.png" alt="1709896897369.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;So the question is, what  is the correct way to set HTTP status code from the instance query handler?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;FlexSim 24.0.2&lt;/P&gt;&lt;/DIV&gt;</description>
    <pubDate>Fri, 08 Mar 2024 11:27:45 GMT</pubDate>
    <dc:creator>sastanin</dc:creator>
    <dc:date>2024-03-08T11:27:45Z</dc:date>
    <item>
      <title>How to set HTTP status in from serverinterface/queryhandlers</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/how-to-set-http-status-in-from-serverinterface-queryhandlers/m-p/13575369#M74731</link>
      <description>&lt;P&gt;&lt;I&gt;[ FlexSim 24.0.2 ]&lt;/I&gt;&lt;/P&gt;&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;We use custom query handlers in MAIN:/project/exec/globals/serverinterface/queryhandlers to interact with our models via FlexSim Webserver, as documented in  &lt;A id="isPasted" href="https://docs.flexsim.com/en/24.0/Reference/DeveloperAdvancedUser/Webserver/Webserver.html#InstanceQueries"&gt;https://docs.flexsim.com/en/24.0/Reference/DeveloperAdvancedUser/Webserver/Webserver.html#InstanceQueries&lt;/A&gt;&lt;/P&gt;&lt;P&gt;What I noticed is that queryinstance always responds with HTTP status code 200 OK, and there doesn't seem a way to set a different status. In particular I'd like to be able to reply with 400 Bad Request or 404 Not Found.&lt;BR /&gt;&lt;BR /&gt;I noticed than many default queryhandlers use this or similar code:&lt;/P&gt;&lt;PRE&gt;setnodestr(replyNode, "HTTP/1.1 404 Not Found");
return replyNode;&lt;/PRE&gt;&lt;P&gt;However, if I try to do the same and  set replyNode to be the header of the response, it still ends up as the body of the response with a status 200.&lt;/P&gt;&lt;P&gt;For instance, this HTTP request&lt;/P&gt;&lt;P&gt;&lt;A href="http://127.0.0.1:10001/webserver.dll?queryinstance=TestModel&amp;amp;instancenum=1&amp;amp;getnodedata=doesnotexist"&gt;http://127.0.0.1:10001/webserver.dll?queryinstance=TestModel&amp;amp;instancenum=1&amp;amp;getnodedata=doesnotexist&lt;/A&gt;&lt;/P&gt;&lt;P&gt;results in a response with HTTP status code 200 and the body fakes to be an HTTP response:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="1709896897369.png"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1522797i60254D8B64E033F5/image-size/large?v=v2&amp;amp;px=999" role="button" title="1709896897369.png" alt="1709896897369.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;So the question is, what  is the correct way to set HTTP status code from the instance query handler?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;FlexSim 24.0.2&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 08 Mar 2024 11:27:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/how-to-set-http-status-in-from-serverinterface-queryhandlers/m-p/13575369#M74731</guid>
      <dc:creator>sastanin</dc:creator>
      <dc:date>2024-03-08T11:27:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to set HTTP status in from serverinterface/queryhandlers</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/how-to-set-http-status-in-from-serverinterface-queryhandlers/m-p/13575370#M74732</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;&lt;A rel="user" href="https://answers.flexsim.com/users/1731/sergea.html" nodeid="1731"&gt;@Serge A&lt;/A&gt; &lt;/P&gt;&lt;P&gt;It looks like we accidentally removed some new line characters that our code was relying on to check for a valid http header.&lt;/P&gt;&lt;P&gt;It used to be like this:&lt;/P&gt;&lt;PRE&gt;setnodestr(replyNode, "HTTP/1.1 404 Not Found\r\n\r\n");&lt;/PRE&gt;&lt;P&gt;When replyNode has byteblock data it first looks for a valid http header. If it finds a valid header it just sends it straight through to the client.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Sorry, this probably would have been useful to know for your previous question about sending JSON text.&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 08 Mar 2024 23:40:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/how-to-set-http-status-in-from-serverinterface-queryhandlers/m-p/13575370#M74732</guid>
      <dc:creator>Jacob_Gillespie</dc:creator>
      <dc:date>2024-03-08T23:40:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to set HTTP status in from serverinterface/queryhandlers</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/how-to-set-http-status-in-from-serverinterface-queryhandlers/m-p/13575371#M74733</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;Hi &lt;A rel="user" href="https://answers.flexsim.com/users/1731/sergea.html" nodeid="1731"&gt;@Serge A&lt;/A&gt;, was Jacob Gillespie's answer helpful? If so, please click the "Accept" button at the bottom of their answer. Or if you still have questions, add a comment and we'll continue the conversation.&lt;/P&gt;&lt;P&gt;If we haven't heard back from you within 3 business days we'll auto-accept an answer, but you can always comment back to reopen your question.&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 14 Mar 2024 06:16:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/how-to-set-http-status-in-from-serverinterface-queryhandlers/m-p/13575371#M74733</guid>
      <dc:creator>Jeanette_Fullmer</dc:creator>
      <dc:date>2024-03-14T06:16:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to set HTTP status in from serverinterface/queryhandlers</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/how-to-set-http-status-in-from-serverinterface-queryhandlers/m-p/13575372#M74734</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;Thank you &lt;A rel="user" href="https://answers.flexsim.com/users/11/jacob.g.html" nodeid="11"&gt;@Jacob Gillespie&lt;/A&gt; , this solution is working perfectly. And indeed, it's also useful to sending application/json responses.&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 19 Mar 2024 08:34:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/how-to-set-http-status-in-from-serverinterface-queryhandlers/m-p/13575372#M74734</guid>
      <dc:creator>sastanin</dc:creator>
      <dc:date>2024-03-19T08:34:25Z</dc:date>
    </item>
  </channel>
</rss>

