POST request Form data manipulation with Nginx Lua
<p>I am using the latest version of OpenResty to perform some manipulations on POST request data using Nginx Lua.  My test Lua script, being called via a <code>rewrite_by_lua_file</code> call is simple</p>

<pre><code>ngx.req.read_body();
local args = ngx.req.get_post_args();
ngx.say(args["a"]);
</code></pre>

<p>To test it I have a simple HTML document</p>

<pre><code>&lt;html&gt;
&lt;head&gt;
&lt;script   
 src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"&gt;   
&lt;/script&gt;
&lt;script&gt;
 $(document).ready(function(){
  $('#btnPOST').click(doPOST);
  $('#btnAJAX').click(doAJAX);
 });

 function doPOST()
 {
  $.post('index.php',{a:2,b:3},afterAJAX);
 }

 function doAJAX()
 {
  var fd = new FormData();
  fd.append('a',2);
  fd.append('b',3);

  $.ajax(
        {url:'index.php',data:fd,cache:false,contentType:false,
         processData:false,
         type:'POST',success:function(d){afterAJAX(d);},error:netError});
  }

  function afterAJAX(d,e)
  {
   debugger;
   alert(d);
  }

  function netError(){alert('error');}
 &lt;/script&gt;
&lt;/head&gt;
 &lt;body&gt;
  &lt;button id='btnPOST'&gt;Post&lt;/button&gt;
  &lt;button id='btnAJAX'&gt;Ajax&lt;/button&gt;
 &lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>Clicking the POST button gives the expected results - the alert box says '2'.</p>

<p>Clicking the AJAX button which is submitting a form OTH returns <code>d=nil</code>.</p>

<p>I am not sure what is going on here. I suspect the issue here is to do with the way multipart form data are sent out.  It seems like Lua/Nginx is missing out on parsing the form data on the multipart boundaries.  However, it is not clear what I should do about it at the Lua end. I'd much appreciate some help</p>