pass API request to proxy server and modify response before send back to client

422 views
Skip to first unread message

Pierre Botte

unread,
Nov 22, 2021, 2:41:31 PM11/22/21
to openresty-en
Hi, here what I'm trying to do : I'm using a tierce API on my website but I would like to modify API XML response in a reverse proxy before send it back to my website in whatever format (xml or json or whatever)

I'm doing fetch request from my website to my proxy server, in my proxy server I do "proxy_pass API_URL" then in body_filter_by_lua I'm modifying my XML response and after I try to parsing my wanted response to json with cjson and apply it to ngx.arg[1]

In content_by_lua i'm doing "ngx.header.content_type = "application/xml; charset=utf-8""

After reloading nginx I succefuly get my response with a curl, I can see it when I visit my proxy url directly but when i'm using my website I receive this error : "error on line 1 at column 1: Document is empty"

How can I succesfuly receive my new json response with my website ?

Or am I doing it wrong ? Is there any easier way ?

Junlong li

unread,
Dec 6, 2021, 8:31:43 AM12/6/21
to openresty-en
1. you should remove the conent-length header in header filter phase
2. you need cache all the body so you can decode the body
3. you can post more error log here

لوجي وبس

unread,
Dec 8, 2021, 4:18:11 AM12/8/21
to openre...@googlegroups.com
financial aid money

--
You received this message because you are subscribed to the Google Groups "openresty-en" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openresty-en...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/openresty-en/82cfc729-f252-4658-ac36-79e2e8edb93cn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages