Skip to content
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

Allow to extract filename from http request body #1613

Merged
merged 1 commit into from
Nov 25, 2021

Conversation

olegrok
Copy link
Contributor

@olegrok olegrok commented Nov 18, 2021

This patch introduces the third argument for metadata of http
request parsing (the second is reserved for an error). Before this
patch function http_read_body returned only file content. However
some of our customers want to know filename as well. It's not so
hard to implement because body headers have such info and the main
goal of this patch is to implement needed logic for header
extraction.


Need for https://github.com/tarantool/tdg2/issues/1207

}
local payload, err, meta = utils.http_read_body(req)
t.assert_equals(payload, 'Content file')
t.assert_equals(err, nil)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
t.assert_equals(err, nil)
t.assert_not(err)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied

Comment on lines 40 to 44
'Content-Disposition: form-data; name="file"; filename="sample.txt"\r\n' ..
'Content-Type: text/plain\r\n' ..
'\r\n' ..
'Content file\r\n' ..
'--c187dde3e9318fcc6509f45f76a89424--'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'Content-Disposition: form-data; name="file"; filename="sample.txt"\r\n' ..
'Content-Type: text/plain\r\n' ..
'\r\n' ..
'Content file\r\n' ..
'--c187dde3e9318fcc6509f45f76a89424--'
'Content-Disposition: form-data; name="file"; filename="sample.txt"\r\n' ..
'Content-Type: text/plain\r\n' ..
'\r\n' ..
'Content file\r\n' ..
'--c187dde3e9318fcc6509f45f76a89424--'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied

cartridge/utils.lua Show resolved Hide resolved
cartridge/utils.lua Show resolved Hide resolved
cartridge/utils.lua Show resolved Hide resolved

function g.test_http_read_body()
local body = '--c187dde3e9318fcc6509f45f76a89424\r\n'..
'Content-Disposition: form-data; name="file"; filename="sample.txt"\r\n' ..
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remember correctly, filename is an optional directive. Could you cover a case when there is none?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Added.

This patch introduces the third argument for metadata of http
request parsing (the second is reserved for an error). Before this
patch function http_read_body returned only file content. However
some of our customers want to know filename as well. It's not so
hard to implement because body headers have such info and the main
goal of this patch is to implement needed logic for header
extraction.
@yngvar-antonsson yngvar-antonsson merged commit 7a84ca3 into master Nov 25, 2021
@yngvar-antonsson yngvar-antonsson deleted the http-filename branch November 25, 2021 12:37
@yngvar-antonsson yngvar-antonsson changed the title allow to extract filename from http request body Allow to extract filename from http request body Jan 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants