Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2020-09-30
16:39 • Ticket [0063cbcada] http: wrong parameter "-headers A" not detected an... artifact: 55ec1c0997 user: oehhar
14:59 • Ticket [0063cbcada]: 6 changes artifact: 8d9b790199 user: jan.nijtmans
12:24 • Ticket [0063cbcada]: 5 changes artifact: dd7b09cf7e user: oehhar
12:21
Ticket [0063cbcada]: From tcl 8.7 on, use "string is dict" instead "string is list" & length %2 == 0... check-in: 78a983fe3d user: oehhar tags: trunk
12:19
Ticket [0063cbcada]: From tcl 8.7 on, use "string is dict" instead "string is list" & length %2 == 0... check-in: 097400e5ad user: oehhar tags: core-8-branch
12:09 • Ticket [0063cbcada] http: wrong parameter "-headers A" not detected an... artifact: c586d096f9 user: oehhar
11:57 • Ticket [0063cbcada]: 5 changes artifact: 56e37bb081 user: sebres
09:37 • Ticket [0063cbcada]: 6 changes artifact: cb0c868d28 user: oehhar
09:30 • Ticket [0063cbcada]: 5 changes artifact: 3c217ad55b user: sebres
08:21 • Ticket [0063cbcada]: 5 changes artifact: bde4748224 user: jan.nijtmans
08:05 • Ticket [0063cbcada]: 6 changes artifact: 73059f9561 user: oehhar
07:58 • Ticket [0063cbcada]: 5 changes artifact: 21758f9fdd user: jan.nijtmans
06:56 • Ticket [0063cbcada]: 6 changes artifact: 2d641db1af user: oehhar
2020-09-29
18:34 • Ticket [0063cbcada]: 5 changes artifact: db4c76c840 user: sebres
16:26 • Closed ticket [0063cbcada]. artifact: 5bdb26b34f user: oehhar
16:23
Ticket [0063cbcada]: check http::geturl -headers parameter to be a dict check-in: 6d8e3c6658 user: oehhar tags: trunk
16:21
Ticket [0063cbcada]: check http::geturl -headers parameter to be a dict check-in: 5c8a8fdddb user: oehhar tags: core-8-branch
16:16
Ticket [0063cbcada]: check http::geturl -headers parameter to be a dict check-in: 8cc32f2b74 user: oehhar tags: core-8-6-branch
15:59 • Ticket [0063cbcada] http: wrong parameter "-headers A" not detected an... artifact: e21a6be390 user: jan.nijtmans
08:31 • Ticket [0063cbcada]: 4 changes artifact: b0ae4776bd user: oehhar
08:15
Ticket [0063cbcada]: check http::geturl -headers parameter to be a dict. check-in: d3dafb6bd0 user: oehhar tags: bug-0063cbcada-http-headers-param-check
2020-09-28
16:05 • Ticket [0063cbcada] http: wrong parameter "-headers A" not detected an... artifact: 7b7aae7df3 user: oehhar
2020-09-27
17:39 • New ticket [0063cbcada]. artifact: 587a9b40ee user: oehhar

http: wrong parameter "-headers A" not detected and sent anyway

Closed / Fixed0063cbcada41024be2d778dc719a64fe2144e0aaCreated 6 years agoUpdated 6 years ago
Descriptionplain2020-09-27 17:39:19
This is just a proposal to enhance the http package, not important.

If the -headers argument is not a dict, communication happens with stange data.
There is no error shown.

My example:
<verbatim>
set hHTTP [http::geturl http://localhost:30030/postfile/test.csv\
	-headers {{Authorization "Basic [binary encode base64 user:pw]"}}\
	-querychannel $hFile\
	-command [namespace code TransmitEnd]\
	-type "text/csv;charset=utf-8"\
	-timeout [expr 180000]
</verbatim>

The issue are the double "{{" in the -headers argument. That looks and is stupid. But it happend to me in deep code nesting so not so obvious...

The sent headers are:
<verbatim>
host       -> 'localhost:30030'
user-agent -> 'Mozilla/5.0 (Windows; U; Windows NT 10.0) http/2.10.0 Tcl/8.6.10'
connection -> 'close'
</verbatim>
My test server errors out due to missing content-length.

This issue is, that the line 1415:
<verbatim>
	dict for {key value} $state(-headers) {
</verbatim>
fails and  is catched by a large general catch.

The http log is:

<verbatim>
^A1 URL http://localhost:30030/postfile/el1068.csv - token ::http::1 
{Using sock0652E0D0 for localhost:30030 - token ::http::1} {}
L():2020-09-27 19:34:32 5 > (::uitk::uitkStateSet State Transmit)
^B1 begin sending request - token ::http::1
{WARNING - if testing, pay special attention to this case (GI) which is seldom executed - token ::http::1}
{Closing socket sock0652E0D0 (no connection info)}
</verbatim>

Thank you,
Harald
Referenced by6
  • 78a983fe3dTicket [0063cbcada]: From tcl 8.7 on, use "string is dict" instead "string is list" & length %2 == 0 to check for a valid dict check-in2020-09-30 12:21:59
  • 097400e5adTicket [0063cbcada]: From tcl 8.7 on, use "string is dict" instead "string is list" & length %2 == 0 to check for a valid dict check-in2020-09-30 12:19:53
  • 6d8e3c6658Ticket [0063cbcada]: check http::geturl -headers parameter to be a dict check-in2020-09-29 16:23:35
  • 5c8a8fdddbTicket [0063cbcada]: check http::geturl -headers parameter to be a dict check-in2020-09-29 16:21:53
  • 8cc32f2b74Ticket [0063cbcada]: check http::geturl -headers parameter to be a dict check-in2020-09-29 16:16:27
  • d3dafb6bd0Ticket [0063cbcada]: check http::geturl -headers parameter to be a dict. check-in2020-09-29 08:15:32
oehharwiki2020-09-28 16:05:55

Implementation proposed with checkin [b069de75ef] within branch [bug-0063cbcada-http-headers-param-check].

I may merge in a week if there are no objections.

Thank you, Harald

oehharwiki2020-09-29 08:31:24

Sorry, solution was based on branch [trunk], and not on [core-8-6-branch]. Here is the commit now in the right branch: [d3dafb6bd0]. The branch is still [bug-0063cbcada-http-headers-param-check].

Thank you, Harald

jan.nijtmanswiki2020-09-29 15:59:50

Nice solution. Thanks!

The added testcase "http-3.2" after "http-3.34" is a duplicate. I assume this one just can be removed. That's my only remark. Further on +1!

oehharwiki2020-09-29 16:26:58

Thanks to the positive feed-back!

Anything is merged now:

Thank you, Harald

sebreswiki2020-09-29 18:34:49

Although this check is nice for negative case, it is a bit questionable how it is implemented currently, at least in positive (good) case if the headers value is initially a dict.

Because then this dict object would shimmer twice:

- once by [string is $type($flag) -strict $value] (or even by [llength $value]) to a list;
- and hereafter by dict for {key value} $state(-headers) back to the dict.

For requests with large headers as dictionary it could be unwanted.

Since 8.7 it is enough to define type of headers as "dict" (without special check with llength). For 8.6 (missing [string is dict ...]) it could be implemented differently (e. g. without check of type, with some dict command, like [dict size]).

oehharwiki2020-09-30 06:56:51

Sebres,

thank you, this is bad news.

I have hoped, that:

  • the "string is list" routines do not shimmer to string, if the value is already a dict, as a dict is always a valid list. This implies, that there is a valid dict representation.
  • the llength routine does not shimmer for dicts, as a dict is always a valid list of length (dict size) * 2. This implies, that there is no string representation and only a dict representation.

So, I see a high optimization potential in those two routines.

On the other hand, do you have a good proposal to check for a valid dict without a catch? I don't like "[catch {dict size $headers}]" to test the format as this pollutes the ::errorX variables.

An alternate approach would be to add a check each time, "-headers" is used. But this will happen within a later stage, so no direct feedback to the command call possible (at least not with the -command option).

Thank you, Harald

jan.nijtmanswiki2020-09-30 07:58:37

I think that "string is list" and "llength" should be smart enough to give the right answers for dicts without shimmering. I'll check if they do, but if they don't that's what should be corrected!

oehharwiki2020-09-30 08:05:50

Thank you, Jan and Sebres! Great that you all care so well.

Thanks, Harald

jan.nijtmanswiki2020-09-30 08:21:29

Looks like sebres is right: currently both "llength" and "string is list" shimmer to list. Actually, "string is list" is implemented by determining the "llength", so those two are actually share the same implementation.

sebreswiki2020-09-30 09:30:46

well, [string is list] can indeed be simply extended to consider dict is a list too, but it is not so simple in case of [llength $dict], because one has to consider whether dictionary is canonical, doesn't own string representation etc, because one could not always calculate it from dict size.

The worse case is here something like that:

% set d {a 1 b 2 c 3 a still_one_a}
a 1 b 2 c 3 a still_one_a
% dict size $d
3
% llength $d
8
so an assumtion that it would always work may be wrong.

oehharwiki2020-09-30 09:37:35

Serbres, thank you for the comment, totally right. But there is a case where it would work.

So a "string is dict" would be great to have (without schimmering if already a dict).

Thank you, Harald

sebreswiki2020-09-30 11:57:38

As already said, [string is dict] is available in 8.7 (since TIP#501)...

Cherry-pick would be simply, but you've to convince TCT to allow that for 8.6.

It is still a puzzle to me why even such a simplest things must be implemented in dev-version only (also if one consider that 8.7th branch is so old and still not released, let alone how long it'll take to get an upgrade in some distributions).

BTW, I changed format of ticket to wiki several times, but every time you change a ticket (add a comment), its format going changed to plain text...
how you do that? old fossil version?

oehharwiki2020-09-30 12:09:24

Dear Sergey,

thank you for the message.

So, at least for core-8-branch and trunk, we could use "string is dict".

And about the "wiki" type. I use the web-interface. Each time, I open the ticket it says format: text. I change it manually to "wiki". WHen you press "Preview", it changes back.

So, thank you for changing it again after this post, if you know how...

Thanks, Harald

oehharwiki2020-09-30 12:24:34

Thank you.

So, "string is dict" is used now in:

For 8.6, we just may remove the patch if the shimmering is a real problem. Nevertheless, I think, it is an improbvement.

Thank you, Harald

jan.nijtmanswiki2020-09-30 14:59:44

Sorry, I couldn't resist tweaking it a little more, with a way that works with 8.6 as well and gives the same error-message. The "catch" is only expensive when there is an error in the -headers dict, not for any other option, so this is IMHO the best I can think of. No ::errorX variables are polluted, except for the (real) error-message we are handling here.

oehharwiki2020-09-30 16:39:24

Informed by PM by Jan:

core-8-branch does not use "string is dict", as the package is installed under "tcl8.6" in the lib folder and thus may be shared between tcl8.6 and tcl8.7.

Thanks for the great work, Harald

Log in (anonymous is fine) to add a comment.