[tarantool-patches] Re: [PATCH] httpc: add checking of headers in httpc:request

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Fri Feb 22 19:01:37 MSK 2019


Hi! Thanks for the fixes! See 3 comments below.

On 19/02/2019 13:49, Roman wrote:
> 
> Hi! Thanks for review.
> 
> On Сб, фев 16, 2019 at 12:17 AM, Vladislav Shpilevoy <v.shpilevoy at tarantool.org> wrote:
>> Hi!
>>
>>         5. Out of 80 symbols.  2. Still out of 80. 
>>
>>     My text editor shows 70 symbols. 
>>
>> Then there is something wrong with your editor, sorry. https://github.com/tarantool/tarantool/blob/romanhabibov/gh-3679-httpc-request/src/lua/httpc.c#L180 Lets count. Here you have 6 tabs - 6 * 8 = 48 symbols. Then you have 55 symbols of "headers must be string or table with \"__tostring\""); 48 + 55 = 103. Also, the error string is not aligned by opening parenthesis. In your email I see, that you have 4 symbols tab, what gives you 79 symbols, but tab width in this file should be 8. So probably you mistakenly set tab width to 4 and the editor shows you < 80 width. Please, fix. 
> Ok. Done.

1. Now you have leading whitespace on line 182. It is clearly visible in
git diff as a bright red point. Please, do self-review before sending
a patch.

> 
> commit c9802592b27cb6986e3e72eb948d8dbfb21baa7e
> Author: Roman Khabibov <roman.habibov at tarantool.org>
> Date: Wed Dec 26 17:49:34 2018 +0300
> 
> httpc: add checking of headers in httpc:request
> Add preprocessing of the request headers. Each header must be 'string' or 'table'
> with '__tostring' metamethod.
> Closes #3679
> 
> diff --git a/src/lua/httpc.c b/src/lua/httpc.c
> index 5f4e2e912..fb012f58b 100644
> --- a/src/lua/httpc.c
> +++ b/src/lua/httpc.c
> @@ -173,6 +173,18 @@ luaT_httpc_request(lua_State *L)
> if (!lua_isnil(L, -1)) {
> lua_pushnil(L);
> while (lua_next(L, -2) != 0) {
> + int header_type = lua_type(L, -1);
> + if (header_type != LUA_TSTRING) {
> + char *err_msg = "headers must be " \
> + "string or table with \"__tostring\"";

2. Please, do not assign a const char string to
a 'char *' variable. Use 'const char *'. Also,
please, properly align strings. This part should
look like this:

			if (header_type != LUA_TSTRING) {
				const char *err_msg =
					"headers must be string or table with "\
					"\"__tostring\"";
				if (header_type != LUA_TTABLE) {

Wrapped string is aligned by the beginning.

> + if (header_type != LUA_TTABLE) {
> + return luaL_error(L, err_msg);
> + } else if (!luaL_getmetafield(L, -1,
> + "__tostring")) {
> + return luaL_error(L, err_msg);
> + }
> + lua_pop(L, 1);
> + }

3. Obviously, there is still something wrong with indentation of your
editor/email agent/whatever else can remove tabs. Please, cope with it.
Before sending a next version into the list, send it to yourself and
check if now the indentation is good.

> if (httpc_set_header(req, "%s: %s",
> lua_tostring(L, -2),
> lua_tostring(L, -1)) < 0) {




More information about the Tarantool-patches mailing list