How to capture certain string in "API request's body" using LUA in NginX.

406 views
Skip to first unread message

Balasekhar Nelli

unread,
Mar 21, 2017, 8:57:38 PM3/21/17
to openresty-en
Hi,

I just statred using LUA for NginX. I have tough time using ngx_lua functions.
What method should I use to capture the certain string from the "API request's body"
---------------------------------------------------------------------------------------------------------------------------


Headers:
DFM-Application-Id: ZaXIZrKT
Dfm-Device-id: android1
DFM-Timestamp: 1489582211
DFM-SHA256-Verifier: 313ecbcb52ef7e09f9fb548325f3530619eb90821db5c880ec3c3b3ca18847c6
Content-Type: application/json
dfm_test: true

Body:
-------
[ {
    "app_id": "sm_id,
    "urlType": "UL",
    "event_type": "deeplink_event",
    "timezone_offset": 19800,
    "timestamp": 1488783314,
    "sdk_version": "4.0.1",
    "url": "https:/url",
    "event_seq": 18,
    "custom_fields": {},
    "platform": "ios",
    "is_first": false,
    "ts": 14887njn83314945,
    "session_id": 148ubbd8783307944
  }]
--------------------------------------------------------------------------------------------------------------------
In the body I want to capture "sdk_version": "4.0.1" . If there is match I have to divert the traffic to certain cluster else to other cluster.

I have tried using " body_filter_by_lua', but failed.

Thanks,
Bala

sjnam

unread,
Mar 24, 2017, 12:52:03 AM3/24/17
to openresty-en
https://github.com/openresty/lua-nginx-module#ngxreqget_body_data

To get request body data, you can use ngx.req.get_body_data method in content_by_lua_block



2017년 3월 22일 수요일 오전 9시 57분 38초 UTC+9, Balasekhar Nelli 님의 말:
Reply all
Reply to author
Forward
0 new messages