-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support multipart/form #32
base: master
Are you sure you want to change the base?
Conversation
lib/resty/requests/multipart.lua
Outdated
@@ -0,0 +1,330 @@ | |||
--https://github.com/pytpeng/lua-multipart |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just manage this dependency by LuaRocks/OPM rather than copy it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
upstream code not merge my pull request yet,so left the problem,Kong/lua-multipart#27
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should suspend this MR until your MR merged by Kong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx,this is better
@@ -69,11 +69,21 @@ local function prepare(url_parts, session, config) | |||
local content | |||
local json = config.json | |||
local body = config.body | |||
local files = config.files | |||
|
|||
if json then | |||
content = cjson.encode(json) | |||
headers["content-length"] = #content | |||
headers["content-type"] = "application/json" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to leave an empty line here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
lib/resty/requests/request.lua
Outdated
if not content_type then | ||
content_type = "multipart/form-data; boundary="..util.choose_boundary() | ||
end | ||
local multipart_body= util.make_multipart_body(files, content_type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style: a space character should be kept before =
.
local multipart_body= util.make_multipart_body(files, content_type) | ||
headers["content-type"] = content_type | ||
headers["content-length"] = #multipart_body | ||
content = multipart_body |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto, leave an empty line here.
lib/resty/requests/util.lua
Outdated
local ngx_gsub = ngx.re.gsub | ||
local base64 = ngx.encode_base64 | ||
local Multipart = require("resty.requests.multipart") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, please keep all require
statements at the top of file, also, do not use capital letters.
lib/resty/requests/util.lua
Outdated
@@ -131,6 +136,9 @@ local function set_config(opts) | |||
-- 4) body | |||
config.body = opts.body | |||
|
|||
-- 4.1) files | |||
config.files = opts.files |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we add an extra to config
, adjusting the table slot size is necessary.
local function choose_boundary() | ||
return str_sub(tostring({}), 10) | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two empty lines are needed to separate functions.
lib/resty/requests/util.lua
Outdated
for _, v in ipairs(files) do | ||
m:set_simple(v[1], v[2], v[3], v[4]) | ||
local m = multipart("", content_type) | ||
for i=1,#files do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style: keep a space before #files
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pytpeng
Could you add some test cases to cover this feature?
yeah
@pytpeng |
…ltipart by LuaRocks/OPM
no message
no message
Add the test cases already 👌
发自我的iPhone
在 2020年3月23日,12:32,Alex Zhang <[email protected]> 写道:
@pytpeng<https://github.com/pytpeng>
Could you add some test cases to cover this feature?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#32 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AHBHDT46KWJFPKVM3BV6TEDRI3Q65ANCNFSM4LRG3TKA>.
|
@pytpeng |
@pytpeng |
@tokers |
add new feature==>support multipart/form ,so we can upload file by requests like python requests