title: Rewrite WebSocket messages via Nginx?
body: <p>Is it possible to rewrite the content of a websocket message proxied through Nginx?</p>
  
  <p>For example, say I've sent a message with the contents <code>JSON.stringify({ auth: 'someIdKey' })</code>. On Nginx, I would to substitute the value of <code>someIdKey</code> to <code>someJwt</code>, then forward it to the proxied upstream resource. I'd also want to do the reverse translation when the upstream resource sends out messages back to the client.</p>
  
  <p>I know how to do this (and am doing this) for HTTP requests, rewriting custom headers to do an on-the-fly translation, but I'm not sure how to approach carrying over the pattern to websocket communication.</p>
  
  <p>I'm using <a href="https://openresty.org/" rel="nofollow noreferrer">OpenResty</a> as my Nginx distribution and am passably-ok at Lua scripting.</p>
  
  <p>Would appreciate any ideas/help.</p>