xref: /OpenGrok/opengrok-indexer/src/test/resources/analysis/lua/sample.lua (revision eeb7e5b33d1bcc524fcc9d1d560447b044e286a4)
1*eeb7e5b3SAdam Hornáček--
2*eeb7e5b3SAdam Hornáček--                                  Apache License
3*eeb7e5b3SAdam Hornáček--                            Version 2.0, January 2004
4*eeb7e5b3SAdam Hornáček--                         http://www.apache.org/licenses/
5*eeb7e5b3SAdam Hornáček--
6*eeb7e5b3SAdam Hornáček--    TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7*eeb7e5b3SAdam Hornáček--
8*eeb7e5b3SAdam Hornáček--    1. Definitions.
9*eeb7e5b3SAdam Hornáček--
10*eeb7e5b3SAdam Hornáček--       "License" shall mean the terms and conditions for use, reproduction,
11*eeb7e5b3SAdam Hornáček--       and distribution as defined by Sections 1 through 9 of this document.
12*eeb7e5b3SAdam Hornáček--
13*eeb7e5b3SAdam Hornáček--       "Licensor" shall mean the copyright owner or entity authorized by
14*eeb7e5b3SAdam Hornáček--       the copyright owner that is granting the License.
15*eeb7e5b3SAdam Hornáček--
16*eeb7e5b3SAdam Hornáček--       "Legal Entity" shall mean the union of the acting entity and all
17*eeb7e5b3SAdam Hornáček--       other entities that control, are controlled by, or are under common
18*eeb7e5b3SAdam Hornáček--       control with that entity. For the purposes of this definition,
19*eeb7e5b3SAdam Hornáček--       "control" means (i) the power, direct or indirect, to cause the
20*eeb7e5b3SAdam Hornáček--       direction or management of such entity, whether by contract or
21*eeb7e5b3SAdam Hornáček--       otherwise, or (ii) ownership of fifty percent (50%) or more of the
22*eeb7e5b3SAdam Hornáček--       outstanding shares, or (iii) beneficial ownership of such entity.
23*eeb7e5b3SAdam Hornáček--
24*eeb7e5b3SAdam Hornáček--       "You" (or "Your") shall mean an individual or Legal Entity
25*eeb7e5b3SAdam Hornáček--       exercising permissions granted by this License.
26*eeb7e5b3SAdam Hornáček--
27*eeb7e5b3SAdam Hornáček--       "Source" form shall mean the preferred form for making modifications,
28*eeb7e5b3SAdam Hornáček--       including but not limited to software source code, documentation
29*eeb7e5b3SAdam Hornáček--       source, and configuration files.
30*eeb7e5b3SAdam Hornáček--
31*eeb7e5b3SAdam Hornáček--       "Object" form shall mean any form resulting from mechanical
32*eeb7e5b3SAdam Hornáček--       transformation or translation of a Source form, including but
33*eeb7e5b3SAdam Hornáček--       not limited to compiled object code, generated documentation,
34*eeb7e5b3SAdam Hornáček--       and conversions to other media types.
35*eeb7e5b3SAdam Hornáček--
36*eeb7e5b3SAdam Hornáček--       "Work" shall mean the work of authorship, whether in Source or
37*eeb7e5b3SAdam Hornáček--       Object form, made available under the License, as indicated by a
38*eeb7e5b3SAdam Hornáček--       copyright notice that is included in or attached to the work
39*eeb7e5b3SAdam Hornáček--       (an example is provided in the Appendix below).
40*eeb7e5b3SAdam Hornáček--
41*eeb7e5b3SAdam Hornáček--       "Derivative Works" shall mean any work, whether in Source or Object
42*eeb7e5b3SAdam Hornáček--       form, that is based on (or derived from) the Work and for which the
43*eeb7e5b3SAdam Hornáček--       editorial revisions, annotations, elaborations, or other modifications
44*eeb7e5b3SAdam Hornáček--       represent, as a whole, an original work of authorship. For the purposes
45*eeb7e5b3SAdam Hornáček--       of this License, Derivative Works shall not include works that remain
46*eeb7e5b3SAdam Hornáček--       separable from, or merely link (or bind by name) to the interfaces of,
47*eeb7e5b3SAdam Hornáček--       the Work and Derivative Works thereof.
48*eeb7e5b3SAdam Hornáček--
49*eeb7e5b3SAdam Hornáček--       "Contribution" shall mean any work of authorship, including
50*eeb7e5b3SAdam Hornáček--       the original version of the Work and any modifications or additions
51*eeb7e5b3SAdam Hornáček--       to that Work or Derivative Works thereof, that is intentionally
52*eeb7e5b3SAdam Hornáček--       submitted to Licensor for inclusion in the Work by the copyright owner
53*eeb7e5b3SAdam Hornáček--       or by an individual or Legal Entity authorized to submit on behalf of
54*eeb7e5b3SAdam Hornáček--       the copyright owner. For the purposes of this definition, "submitted"
55*eeb7e5b3SAdam Hornáček--       means any form of electronic, verbal, or written communication sent
56*eeb7e5b3SAdam Hornáček--       to the Licensor or its representatives, including but not limited to
57*eeb7e5b3SAdam Hornáček--       communication on electronic mailing lists, source code control systems,
58*eeb7e5b3SAdam Hornáček--       and issue tracking systems that are managed by, or on behalf of, the
59*eeb7e5b3SAdam Hornáček--       Licensor for the purpose of discussing and improving the Work, but
60*eeb7e5b3SAdam Hornáček--       excluding communication that is conspicuously marked or otherwise
61*eeb7e5b3SAdam Hornáček--       designated in writing by the copyright owner as "Not a Contribution."
62*eeb7e5b3SAdam Hornáček--
63*eeb7e5b3SAdam Hornáček--       "Contributor" shall mean Licensor and any individual or Legal Entity
64*eeb7e5b3SAdam Hornáček--       on behalf of whom a Contribution has been received by Licensor and
65*eeb7e5b3SAdam Hornáček--       subsequently incorporated within the Work.
66*eeb7e5b3SAdam Hornáček--
67*eeb7e5b3SAdam Hornáček--    2. Grant of Copyright License. Subject to the terms and conditions of
68*eeb7e5b3SAdam Hornáček--       this License, each Contributor hereby grants to You a perpetual,
69*eeb7e5b3SAdam Hornáček--       worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70*eeb7e5b3SAdam Hornáček--       copyright license to reproduce, prepare Derivative Works of,
71*eeb7e5b3SAdam Hornáček--       publicly display, publicly perform, sublicense, and distribute the
72*eeb7e5b3SAdam Hornáček--       Work and such Derivative Works in Source or Object form.
73*eeb7e5b3SAdam Hornáček--
74*eeb7e5b3SAdam Hornáček--    3. Grant of Patent License. Subject to the terms and conditions of
75*eeb7e5b3SAdam Hornáček--       this License, each Contributor hereby grants to You a perpetual,
76*eeb7e5b3SAdam Hornáček--       worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77*eeb7e5b3SAdam Hornáček--       (except as stated in this section) patent license to make, have made,
78*eeb7e5b3SAdam Hornáček--       use, offer to sell, sell, import, and otherwise transfer the Work,
79*eeb7e5b3SAdam Hornáček--       where such license applies only to those patent claims licensable
80*eeb7e5b3SAdam Hornáček--       by such Contributor that are necessarily infringed by their
81*eeb7e5b3SAdam Hornáček--       Contribution(s) alone or by combination of their Contribution(s)
82*eeb7e5b3SAdam Hornáček--       with the Work to which such Contribution(s) was submitted. If You
83*eeb7e5b3SAdam Hornáček--       institute patent litigation against any entity (including a
84*eeb7e5b3SAdam Hornáček--       cross-claim or counterclaim in a lawsuit) alleging that the Work
85*eeb7e5b3SAdam Hornáček--       or a Contribution incorporated within the Work constitutes direct
86*eeb7e5b3SAdam Hornáček--       or contributory patent infringement, then any patent licenses
87*eeb7e5b3SAdam Hornáček--       granted to You under this License for that Work shall terminate
88*eeb7e5b3SAdam Hornáček--       as of the date such litigation is filed.
89*eeb7e5b3SAdam Hornáček--
90*eeb7e5b3SAdam Hornáček--    4. Redistribution. You may reproduce and distribute copies of the
91*eeb7e5b3SAdam Hornáček--       Work or Derivative Works thereof in any medium, with or without
92*eeb7e5b3SAdam Hornáček--       modifications, and in Source or Object form, provided that You
93*eeb7e5b3SAdam Hornáček--       meet the following conditions:
94*eeb7e5b3SAdam Hornáček--
95*eeb7e5b3SAdam Hornáček--       (a) You must give any other recipients of the Work or
96*eeb7e5b3SAdam Hornáček--           Derivative Works a copy of this License; and
97*eeb7e5b3SAdam Hornáček--
98*eeb7e5b3SAdam Hornáček--       (b) You must cause any modified files to carry prominent notices
99*eeb7e5b3SAdam Hornáček--           stating that You changed the files; and
100*eeb7e5b3SAdam Hornáček--
101*eeb7e5b3SAdam Hornáček--       (c) You must retain, in the Source form of any Derivative Works
102*eeb7e5b3SAdam Hornáček--           that You distribute, all copyright, patent, trademark, and
103*eeb7e5b3SAdam Hornáček--           attribution notices from the Source form of the Work,
104*eeb7e5b3SAdam Hornáček--           excluding those notices that do not pertain to any part of
105*eeb7e5b3SAdam Hornáček--           the Derivative Works; and
106*eeb7e5b3SAdam Hornáček--
107*eeb7e5b3SAdam Hornáček--       (d) If the Work includes a "NOTICE" text file as part of its
108*eeb7e5b3SAdam Hornáček--           distribution, then any Derivative Works that You distribute must
109*eeb7e5b3SAdam Hornáček--           include a readable copy of the attribution notices contained
110*eeb7e5b3SAdam Hornáček--           within such NOTICE file, excluding those notices that do not
111*eeb7e5b3SAdam Hornáček--           pertain to any part of the Derivative Works, in at least one
112*eeb7e5b3SAdam Hornáček--           of the following places: within a NOTICE text file distributed
113*eeb7e5b3SAdam Hornáček--           as part of the Derivative Works; within the Source form or
114*eeb7e5b3SAdam Hornáček--           documentation, if provided along with the Derivative Works; or,
115*eeb7e5b3SAdam Hornáček--           within a display generated by the Derivative Works, if and
116*eeb7e5b3SAdam Hornáček--           wherever such third-party notices normally appear. The contents
117*eeb7e5b3SAdam Hornáček--           of the NOTICE file are for informational purposes only and
118*eeb7e5b3SAdam Hornáček--           do not modify the License. You may add Your own attribution
119*eeb7e5b3SAdam Hornáček--           notices within Derivative Works that You distribute, alongside
120*eeb7e5b3SAdam Hornáček--           or as an addendum to the NOTICE text from the Work, provided
121*eeb7e5b3SAdam Hornáček--           that such additional attribution notices cannot be construed
122*eeb7e5b3SAdam Hornáček--           as modifying the License.
123*eeb7e5b3SAdam Hornáček--
124*eeb7e5b3SAdam Hornáček--       You may add Your own copyright statement to Your modifications and
125*eeb7e5b3SAdam Hornáček--       may provide additional or different license terms and conditions
126*eeb7e5b3SAdam Hornáček--       for use, reproduction, or distribution of Your modifications, or
127*eeb7e5b3SAdam Hornáček--       for any such Derivative Works as a whole, provided Your use,
128*eeb7e5b3SAdam Hornáček--       reproduction, and distribution of the Work otherwise complies with
129*eeb7e5b3SAdam Hornáček--       the conditions stated in this License.
130*eeb7e5b3SAdam Hornáček--
131*eeb7e5b3SAdam Hornáček--    5. Submission of Contributions. Unless You explicitly state otherwise,
132*eeb7e5b3SAdam Hornáček--       any Contribution intentionally submitted for inclusion in the Work
133*eeb7e5b3SAdam Hornáček--       by You to the Licensor shall be under the terms and conditions of
134*eeb7e5b3SAdam Hornáček--       this License, without any additional terms or conditions.
135*eeb7e5b3SAdam Hornáček--       Notwithstanding the above, nothing herein shall supersede or modify
136*eeb7e5b3SAdam Hornáček--       the terms of any separate license agreement you may have executed
137*eeb7e5b3SAdam Hornáček--       with Licensor regarding such Contributions.
138*eeb7e5b3SAdam Hornáček--
139*eeb7e5b3SAdam Hornáček--    6. Trademarks. This License does not grant permission to use the trade
140*eeb7e5b3SAdam Hornáček--       names, trademarks, service marks, or product names of the Licensor,
141*eeb7e5b3SAdam Hornáček--       except as required for reasonable and customary use in describing the
142*eeb7e5b3SAdam Hornáček--       origin of the Work and reproducing the content of the NOTICE file.
143*eeb7e5b3SAdam Hornáček--
144*eeb7e5b3SAdam Hornáček--    7. Disclaimer of Warranty. Unless required by applicable law or
145*eeb7e5b3SAdam Hornáček--       agreed to in writing, Licensor provides the Work (and each
146*eeb7e5b3SAdam Hornáček--       Contributor provides its Contributions) on an "AS IS" BASIS,
147*eeb7e5b3SAdam Hornáček--       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148*eeb7e5b3SAdam Hornáček--       implied, including, without limitation, any warranties or conditions
149*eeb7e5b3SAdam Hornáček--       of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150*eeb7e5b3SAdam Hornáček--       PARTICULAR PURPOSE. You are solely responsible for determining the
151*eeb7e5b3SAdam Hornáček--       appropriateness of using or redistributing the Work and assume any
152*eeb7e5b3SAdam Hornáček--       risks associated with Your exercise of permissions under this License.
153*eeb7e5b3SAdam Hornáček--
154*eeb7e5b3SAdam Hornáček--    8. Limitation of Liability. In no event and under no legal theory,
155*eeb7e5b3SAdam Hornáček--       whether in tort (including negligence), contract, or otherwise,
156*eeb7e5b3SAdam Hornáček--       unless required by applicable law (such as deliberate and grossly
157*eeb7e5b3SAdam Hornáček--       negligent acts) or agreed to in writing, shall any Contributor be
158*eeb7e5b3SAdam Hornáček--       liable to You for damages, including any direct, indirect, special,
159*eeb7e5b3SAdam Hornáček--       incidental, or consequential damages of any character arising as a
160*eeb7e5b3SAdam Hornáček--       result of this License or out of the use or inability to use the
161*eeb7e5b3SAdam Hornáček--       Work (including but not limited to damages for loss of goodwill,
162*eeb7e5b3SAdam Hornáček--       work stoppage, computer failure or malfunction, or any and all
163*eeb7e5b3SAdam Hornáček--       other commercial damages or losses), even if such Contributor
164*eeb7e5b3SAdam Hornáček--       has been advised of the possibility of such damages.
165*eeb7e5b3SAdam Hornáček--
166*eeb7e5b3SAdam Hornáček--    9. Accepting Warranty or Additional Liability. While redistributing
167*eeb7e5b3SAdam Hornáček--       the Work or Derivative Works thereof, You may choose to offer,
168*eeb7e5b3SAdam Hornáček--       and charge a fee for, acceptance of support, warranty, indemnity,
169*eeb7e5b3SAdam Hornáček--       or other liability obligations and/or rights consistent with this
170*eeb7e5b3SAdam Hornáček--       License. However, in accepting such obligations, You may act only
171*eeb7e5b3SAdam Hornáček--       on Your own behalf and on Your sole responsibility, not on behalf
172*eeb7e5b3SAdam Hornáček--       of any other Contributor, and only if You agree to indemnify,
173*eeb7e5b3SAdam Hornáček--       defend, and hold each Contributor harmless for any liability
174*eeb7e5b3SAdam Hornáček--       incurred by, or claims asserted against, such Contributor by reason
175*eeb7e5b3SAdam Hornáček--       of your accepting any such warranty or additional liability.
176*eeb7e5b3SAdam Hornáček--
177*eeb7e5b3SAdam Hornáček--    END OF TERMS AND CONDITIONS
178*eeb7e5b3SAdam Hornáček--
179*eeb7e5b3SAdam Hornáček--    APPENDIX: How to apply the Apache License to your work.
180*eeb7e5b3SAdam Hornáček--
181*eeb7e5b3SAdam Hornáček--       To apply the Apache License to your work, attach the following
182*eeb7e5b3SAdam Hornáček--       boilerplate notice, with the fields enclosed by brackets "[]"
183*eeb7e5b3SAdam Hornáček--       replaced with your own identifying information. (Don't include
184*eeb7e5b3SAdam Hornáček--       the brackets!)  The text should be enclosed in the appropriate
185*eeb7e5b3SAdam Hornáček--       comment syntax for the file format. We also recommend that a
186*eeb7e5b3SAdam Hornáček--       file or class name and description of purpose be included on the
187*eeb7e5b3SAdam Hornáček--       same "printed page" as the copyright notice for easier
188*eeb7e5b3SAdam Hornáček--       identification within third-party archives.
189*eeb7e5b3SAdam Hornáček--
190*eeb7e5b3SAdam Hornáček--    Copyright 2016-2017 Kong Inc.
191*eeb7e5b3SAdam Hornáček--
192*eeb7e5b3SAdam Hornáček--    Licensed under the Apache License, Version 2.0 (the "License");
193*eeb7e5b3SAdam Hornáček--    you may not use this file except in compliance with the License.
194*eeb7e5b3SAdam Hornáček--    You may obtain a copy of the License at
195*eeb7e5b3SAdam Hornáček--
196*eeb7e5b3SAdam Hornáček--        http://www.apache.org/licenses/LICENSE-2.0
197*eeb7e5b3SAdam Hornáček--
198*eeb7e5b3SAdam Hornáček--    Unless required by applicable law or agreed to in writing, software
199*eeb7e5b3SAdam Hornáček--    distributed under the License is distributed on an "AS IS" BASIS,
200*eeb7e5b3SAdam Hornáček--    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201*eeb7e5b3SAdam Hornáček--    See the License for the specific language governing permissions and
202*eeb7e5b3SAdam Hornáček--    limitations under the License.
203*eeb7e5b3SAdam Hornáček
204*eeb7e5b3SAdam Hornáčeklocal pcall = pcall
205*eeb7e5b3SAdam Hornáčeklocal ngx_log = ngx.log
206*eeb7e5b3SAdam Hornáčeklocal ERR = ngx.ERR
207*eeb7e5b3SAdam Hornáček
208*eeb7e5b3SAdam Hornáček
209*eeb7e5b3SAdam Hornáčeklocal _M = {}
210*eeb7e5b3SAdam Hornáček
211*eeb7e5b3SAdam Hornáček
212*eeb7e5b3SAdam Hornáčekdo
213*eeb7e5b3SAdam Hornáček  local multipart = require "multipart"
214*eeb7e5b3SAdam Hornáček  local cjson     = require "cjson.safe"
215*eeb7e5b3SAdam Hornáček
216*eeb7e5b3SAdam Hornáček
217*eeb7e5b3SAdam Hornáček  local str_find              = string.find
218*eeb7e5b3SAdam Hornáček  local str_format            = string.format
219*eeb7e5b3SAdam Hornáček  local ngx_req_get_post_args = ngx.req.get_post_args
220*eeb7e5b3SAdam Hornáček  local ngx_req_get_body_data = ngx.req.get_body_data
221*eeb7e5b3SAdam Hornáček
222*eeb7e5b3SAdam Hornáček
223*eeb7e5b3SAdam Hornáček  local MIME_TYPES = {
224*eeb7e5b3SAdam Hornáček    form_url_encoded = 1,
225*eeb7e5b3SAdam Hornáček    json             = 2,
226*eeb7e5b3SAdam Hornáček    xml              = 3,
227*eeb7e5b3SAdam Hornáček    multipart        = 4,
228*eeb7e5b3SAdam Hornáček    text             = 5,
229*eeb7e5b3SAdam Hornáček    html             = 6,
230*eeb7e5b3SAdam Hornáček  }
231*eeb7e5b3SAdam Hornáček
232*eeb7e5b3SAdam Hornáček
233*eeb7e5b3SAdam Hornáček  local ERRORS     = {
234*eeb7e5b3SAdam Hornáček    no_ct          = 1 + 0xFFFF - 0XFFFF,
235*eeb7e5b3SAdam Hornáček    [1]            = "don't know how to parse request body (no Content-Type)",
236*eeb7e5b3SAdam Hornáček    unknown_ct     = 2,
237*eeb7e5b3SAdam Hornáček    [2]            = "don't know how to parse request body (" ..
238*eeb7e5b3SAdam Hornáček                     "unknown Content-Type '%s')",
239*eeb7e5b3SAdam Hornáček    unsupported_ct = 3,
240*eeb7e5b3SAdam Hornáček    [3]            = "don't know how to parse request body (" ..
241*eeb7e5b3SAdam Hornáček                     "can't decode Content-Type '%s')",
242*eeb7e5b3SAdam Hornáček  }
243*eeb7e5b3SAdam Hornáček
244*eeb7e5b3SAdam Hornáček
245*eeb7e5b3SAdam Hornáček  _M.req_mime_types  = MIME_TYPES
246*eeb7e5b3SAdam Hornáček  _M.req_body_errors = ERRORS
247*eeb7e5b3SAdam Hornáček
248*eeb7e5b3SAdam Hornáček
249*eeb7e5b3SAdam Hornáček  local MIME_DECODERS = {
250*eeb7e5b3SAdam Hornáček    [MIME_TYPES.multipart] = function(content_type)
251*eeb7e5b3SAdam Hornáček      local raw_body = ngx_req_get_body_data()
252*eeb7e5b3SAdam Hornáček      local args     = multipart(raw_body, content_type):get_all()
253*eeb7e5b3SAdam Hornáček
254*eeb7e5b3SAdam Hornáček      return args, raw_body
255*eeb7e5b3SAdam Hornáček    end,
256*eeb7e5b3SAdam Hornáček
257*eeb7e5b3SAdam Hornáček    [MIME_TYPES.json] = function()
258*eeb7e5b3SAdam Hornáček      local raw_body  = ngx_req_get_body_data()
259*eeb7e5b3SAdam Hornáček      local args, err = cjson.decode(raw_body)
260*eeb7e5b3SAdam Hornáček      if err then
261*eeb7e5b3SAdam Hornáček        ngx_log(ERR, "could not decode JSON body args: ", err)
262*eeb7e5b3SAdam Hornáček        return {}, raw_body
263*eeb7e5b3SAdam Hornáček      end
264*eeb7e5b3SAdam Hornáček
265*eeb7e5b3SAdam Hornáček      return args, raw_body
266*eeb7e5b3SAdam Hornáček    end,
267*eeb7e5b3SAdam Hornáček
268*eeb7e5b3SAdam Hornáček    [MIME_TYPES.form_url_encoded] = function()
269*eeb7e5b3SAdam Hornáček      local ok, res, err = pcall(ngx_req_get_post_args)
270*eeb7e5b3SAdam Hornáček      if not ok or err then
271*eeb7e5b3SAdam Hornáček        local msg = res and res or err
272*eeb7e5b3SAdam Hornáček        ngx_log(ERR, "could not get body args: ", msg)
273*eeb7e5b3SAdam Hornáček        return {}
274*eeb7e5b3SAdam Hornáček      end
275*eeb7e5b3SAdam Hornáček
276*eeb7e5b3SAdam Hornáček      --[=[ don't read raw_body if not necessary ]]
277*eeb7e5b3SAdam Hornáček      -- if we called get_body_args(), we only want the parsed body ]=]
278*eeb7e5b3SAdam Hornáček      return res
279*eeb7e5b3SAdam Hornáček    end,
280*eeb7e5b3SAdam Hornáček  }
281*eeb7e5b3SAdam Hornáček
282*eeb7e5b3SAdam Hornáček
283*eeb7e5b3SAdam Hornáček  local function get_body_info()
284*eeb7e5b3SAdam Hornáček    local content_type = ngx.var.http_content_type
285*eeb7e5b3SAdam Hornáček
286*eeb7e5b3SAdam Hornáček    if not content_type or content_type == "" then
287*eeb7e5b3SAdam Hornáček      ngx_log(ERR, ERRORS[ERRORS.no_ct])
288*eeb7e5b3SAdam Hornáček
289*eeb7e5b3SAdam Hornáček      return {}, ERRORS.no_ct
290*eeb7e5b3SAdam Hornáček    end
291*eeb7e5b3SAdam Hornáček
292*eeb7e5b3SAdam Hornáček    local req_mime
293*eeb7e5b3SAdam Hornáček
294*eeb7e5b3SAdam Hornáček    if str_find(content_type, "multipart/form-data", nil, true) then
295*eeb7e5b3SAdam Hornáček      req_mime = MIME_TYPES.multipart
296*eeb7e5b3SAdam Hornáček
297*eeb7e5b3SAdam Hornáček    elseif str_find(content_type, "application/json", nil, true) then
298*eeb7e5b3SAdam Hornáček      req_mime = MIME_TYPES.json
299*eeb7e5b3SAdam Hornáček
300*eeb7e5b3SAdam Hornáček    elseif str_find(content_type, "application/www-form-urlencoded", nil, true) or
301*eeb7e5b3SAdam Hornáček           str_find(content_type, "application/x-www-form-urlencoded", nil, true)
302*eeb7e5b3SAdam Hornáček    then
303*eeb7e5b3SAdam Hornáček      req_mime = MIME_TYPES.form_url_encoded
304*eeb7e5b3SAdam Hornáček
305*eeb7e5b3SAdam Hornáček    elseif str_find(content_type, [=[text/plain]=], nil, true) then
306*eeb7e5b3SAdam Hornáček      req_mime = MIME_TYPES.text
307*eeb7e5b3SAdam Hornáček
308*eeb7e5b3SAdam Hornáček    elseif str_find(content_type, "text/html", nil, true) then
309*eeb7e5b3SAdam Hornáček      req_mime = MIME_TYPES.html
310*eeb7e5b3SAdam Hornáček
311*eeb7e5b3SAdam Hornáček    elseif str_find(content_type, "application/xml", nil, true) or
312*eeb7e5b3SAdam Hornáček           str_find(content_type, "text/xml", nil, true)        or
313*eeb7e5b3SAdam Hornáček           str_find(content_type, "application/soap+xml", nil, true)
314*eeb7e5b3SAdam Hornáček    then
315*eeb7e5b3SAdam Hornáček      -- considering SOAP 1.1 (text/xml) and SOAP 1.2 (application/soap+xml)
316*eeb7e5b3SAdam Hornáček      -- as XML only for now.
317*eeb7e5b3SAdam Hornáček      req_mime = MIME_TYPES.xml
318*eeb7e5b3SAdam Hornáček    end
319*eeb7e5b3SAdam Hornáček
320*eeb7e5b3SAdam Hornáček    if not req_mime then
321*eeb7e5b3SAdam Hornáček      -- unknown Content-Type
322*eeb7e5b3SAdam Hornáček      ngx_log(ERR, str_format(ERRORS[ERRORS.unsupported_ct], content_type))
323*eeb7e5b3SAdam Hornáček
324*eeb7e5b3SAdam Hornáček      return {}, ERRORS.unknown_ct
325*eeb7e5b3SAdam Hornáček    end
326*eeb7e5b3SAdam Hornáček
327*eeb7e5b3SAdam Hornáček    if not MIME_DECODERS[req_mime] then
328*eeb7e5b3SAdam Hornáček      -- known Content-Type, but cannot decode
329*eeb7e5b3SAdam Hornáček      ngx_log(ERR, str_format(ERRORS[ERRORS.unsupported_ct], content_type))
330*eeb7e5b3SAdam Hornáček
331*eeb7e5b3SAdam Hornáček      return {}, ERRORS.unsupported_ct, nil, req_mime
332*eeb7e5b3SAdam Hornáček    end
333*eeb7e5b3SAdam Hornáček
334*eeb7e5b3SAdam Hornáček    -- decoded Content-Type
335*eeb7e5b3SAdam Hornáček    local args, raw_body = MIME_DECODERS[req_mime](content_type)
336*eeb7e5b3SAdam Hornáček
337*eeb7e5b3SAdam Hornáček    return args, nil, raw_body, req_mime
338*eeb7e5b3SAdam Hornáček  end
339*eeb7e5b3SAdam Hornáček
340*eeb7e5b3SAdam Hornáček
341*eeb7e5b3SAdam Hornáček  function _M.get_body_args()
342*eeb7e5b3SAdam Hornáček    -- only return args
343*eeb7e5b3SAdam Hornáček    return (get_body_info())
344*eeb7e5b3SAdam Hornáček  end
345*eeb7e5b3SAdam Hornáček
346*eeb7e5b3SAdam Hornáček
347*eeb7e5b3SAdam Hornáček  function _M.get_body_info()
348*eeb7e5b3SAdam Hornáček    local args, err_code, raw_body, req_mime0 = get_body_info()
349*eeb7e5b3SAdam Hornáček    if not raw_body then
350*eeb7e5b3SAdam Hornáček      -- if our body was form-urlencoded and read via ngx.req.get_post_args()
351*eeb7e5b3SAdam Hornáček      -- we need to retrieve the raw body because it was not retrieved by the
352*eeb7e5b3SAdam Hornáček      -- decoder
353*eeb7e5b3SAdam Hornáček      raw_body = ngx_req_get_body_data()
354*eeb7e5b3SAdam Hornáček    end
355*eeb7e5b3SAdam Hornáček
356*eeb7e5b3SAdam Hornáček    return args, err_code, raw_body, req_mime
357*eeb7e5b3SAdam Hornáček  end
358*eeb7e5b3SAdam Hornáčekend
359*eeb7e5b3SAdam Hornáček
360*eeb7e5b3SAdam Hornáček
361*eeb7e5b3SAdam Hornáčekreturn _M
362*eeb7e5b3SAdam Hornáčekreturn 'http://example.com?a='
363*eeb7e5b3SAdam Hornáčekreturn [=[http://example.com?a=]=]
364*eeb7e5b3SAdam Hornáčekreturn "http://example.com?a="
365*eeb7e5b3SAdam Hornáčekreturn 'http://example.com?a=\'b\''
366