From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id D410227471 for ; Mon, 25 Feb 2019 10:21:34 -0500 (EST) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9s7KgsmuIQBP for ; Mon, 25 Feb 2019 10:21:34 -0500 (EST) Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id D8CFC27118 for ; Mon, 25 Feb 2019 10:21:33 -0500 (EST) Subject: [tarantool-patches] Re: [PATCH v1 1/1] http: fix httpc auto-managed headers References: <9099f8a339c278e3a5dac683923d13c7ee470ce9.1550761676.git.kshcherbatov@tarantool.org> <80130a1b-84ad-5f90-9422-95bb0a1e67cb@tarantool.org> From: Kirill Shcherbatov Message-ID: <998b800b-acc1-f0c8-1fd3-322d0c04f657@tarantool.org> Date: Mon, 25 Feb 2019 18:21:31 +0300 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org, Vladislav Shpilevoy Hi! Thank you for review. > 1. The email is utterly corrupted - all the indentation is lost. Please, > do not copypaste patches into an email without proper preparations. Ok. > 2. In such a small function it is already clear, that you > do not need this single 'goto error'. Just process that error > here. Done. > 3. Use doxygen style.> 4. I do not understand the name. Is it supposed to be a check? > Then, firstly, for checks we usually use '_is/has_' > naming template. But anyway it is not a check, because it changes > the mask. Come up with a better name, or use, for example, this: > > httpc_set_header_bit /** * Update bitmask of the http request headers that httpc may set * automatically. In case of reserved pattern is found in header, * routine sets corresponding bit in auto_headers_mask. * Returns -1 when header is reserved and it's bit is already set * in auto_headers_mask; 0 otherwise, * @param auto_headers_mask The bitmask of httpc-auto-managed * headers to pointer. * @param header The HTTP header string. * @retval 0 When specified header is not auto-managed or when * corresponding bit was not set in auto_headers_mask. * @retval -1 otherwise. */ static int httpc_set_header_bit(uint8_t *auto_headers_mask, const char *header) > 5. The code below looks like Java. Please, rename to just 'name' > and 'len'.> 6. I do not see any point in storing lengths here, because > anyway you can not use memcmp. Strncasecmp below will check > for terminating zero in both parameters anyway. It is not so, because we must compare just only prefix of specified length. For more details, show 9th comment. > 7. We have lengthof in trivia/utils.h. /* * The sequence of managed headers must be sorted to * stop scan when strcasecmp < 0. The header is expected * to be formated with "%s: %s" pattern, so direct size * verification is redundant. */ struct { const char *name; int len; } managed_headers[] = { {"Accept: ", sizeof("Accept: ") - 1}, {"Connection: ", sizeof("Connection: ") - 1}, {"Content-Length: ", sizeof("Content-Length: ") - 1}, {"Keep-Alive: ", sizeof("Keep-Alive: ") - 1}, }; > 8. Please, do not use non standard types without necessity. > https://github.com/tarantool/tarantool/issues/2161 for (int i = 0; i < managed_headers_cnt; i++) { > 9. As I said at least 2 times for one of previous issues, strncmp does > not work properly without additional checks. Your code will consider > 'Acceptttttt' and 'Accept' to be equal. Please, fix that and add a test. It is not so here, because header is a string that have strong format "%s: %s" I've modified managed_headers array below to use "%s: " prefix. Here It is not a bug, but feature =) > 10. I propose you to store const headers of httpc_managed_headers in a sorted > order. Sorted by the header names. Then, if during an iteration in the cycle > above you see, that strncasecmp() returned < 0, you can return without > further checks. I hope, that you understand why. > > Another option is a binary search, but I think, that it is overkill here. Implemented. > 11. Firstly, it is a method of http_request, and should have > prefix 'http_request_'. But as I see, it is a common style > violation for this library, so lets turn the blind eye to it. > > Secondly, personally I would like 'httpc_set_url', because it > looks shorter. And because 'resource' confused me at a first > glance. > > Thirdly, please, move that function implementation below > httpc_request_new to reduce diff. Done. > 12. Do not put references 'for details' to some internal > functions. They likely to be changed, or renamed, or deleted, > and your reference will be useless. Explain here everything. /** * A bitmask of the http request headers from among * the headers that httpc can set automatically. * Each bit represents some auto-managed HTTP header. * This allows to prevent set them twice. */ uint8_t auto_headers_mask; > 13. > - Please, start each @