• Tcllib httpd package issues

    From Danilo Chang@21:1/5 to All on Sat Nov 11 04:41:03 2023
    I notice tcllib httpd package has some issues (source code and document),
    so I test tcllib httpd v4.3.5 to check its status.

    Then I create 2 tickets for httpd package, c0e70192dd45ea7b26cc8470a4025fe9e8b70d16 - httpd ::httpd::content.file method content issue
    9d1f4444f144619857bd281beb24199b005d2edc - httpd Minimal Example not work

    When I check the tickets list, I find below cases also about httpd Example: 85d8548e0acf775c153f381cb4642d89ba1a41f3 79c916b904bb11c028feefd9251f2fa18b637b08 0924679869f8a16ee82659fcca25b07d612d2ab7 1b43369dbc9e4ab14533b5a40f0ac41976f308fc

    Tcllib examples/httpd/httpd.tcl is OK,
    but Tcler's wiki and tcllib httpd document example both not work.


    1. Tcler's wiki example

    It maybe the version upgrade issue.
    (It is about issue 79c916b904bb11c028feefd9251f2fa18b637b08)

    The solution is to remove the "HTTPD start" this line.

    The reason is ::httpd::server constructor finally call `start` method,
    so you don't need to call it again.
    This is why you will get "couldn't open socket: address already in use" message.

    I ref other examples and update the example code in Tcler's wiki,
    the example works in my environment for httpd v4.3.5.


    2. Tcllib httpd document Minimal Example

    It maybe the version upgrade issue.
    (It is about issues
    85d8548e0acf775c153f381cb4642d89ba1a41f3, 0924679869f8a16ee82659fcca25b07d612d2ab7, 1b43369dbc9e4ab14533b5a40f0ac41976f308fc, 9d1f4444f144619857bd281beb24199b005d2edc)

    Tcllib httpd document Minimal Example is terrible for new user.
    I find below problems:
    1) Class httpd::server::dispatch for plugin dispatch does not exist
    2) ::reply.hello results in error (should use clay::define to implement content)
    3) uri add behavior is wrong, should use {content reply.hello} to replace reply.hello

    So the Minimal Example in tcllib httpd document should change to -

    clay::define ::reply.hello {
    method content {} {
    my puts "<HTML><HEAD><TITLE>IRM Dispatch Server</TITLE></HEAD><BODY>"
    my puts "<h1>Hello World!</h1>"
    my puts </BODY></HTML>
    }
    }
    ::httpd::server create HTTPD port 8015 myaddr 127.0.0.1 doc_root ~/htdocs
    HTTPD plugin dispatch ::httpd::plugin.dict_dispatch
    HTTPD uri add * /hello [list mixin {content reply.hello}]


    3. httpd ::httpd::content.file method content issue

    (It is about issue c0e70192dd45ea7b26cc8470a4025fe9e8b70d16)

    I try to create a server to serve static files for myself.
    If the URL is
    http://localhost:8015/Language/index.html

    Then httpd will try to find
    http://localhost:8015/Language/index.html/

    Then results in "Listing contents of /Language/index.html/"
    The behavior is wrong, because I request to get index.html file content.

    If you have second level directory and try to get index.html,
    it is not as you expect in current httpd code base.

    After check the source code, I think because below conditions:

    if {[file isdirectory $local_file] || [file tail $local_file] in {index index.html index.tml index.md}} {

    The condition [file tail $local_file] in {index index.html index.tml index.md} results in error case.
    If it is a feature for httpd, for what? I feel the condition is strange and result in errors.
    So I think it needs to clarify. And if it is not a feature and does not influence something, it is good to remove the second condition.


    4. Tcllib/httpd: Directory listing & error pages try to load /images/etoyoc-banner.jpg

    (It is about issue 7987932aaae1de26db7c2dcf82b6fba9b76e7e3b)

    When producing a directory listing with Tcllib/httpd,
    the generated HTML code tries to display the (non-existent & unconfigurable) image '/images/etoyoc-banner.jpg'.

    It is ::httpd::reply method html_header behavior, below is the code.

    if {[dict exists $args banner]} {
    append result "<img src=\"[dict get $args banner]\">"
    } else {
    append result {<img src="/images/etoyoc-banner.jpg">}
    }

    I suggest change to below code:

    if {[dict exists $args banner]} {
    append result "<img src=\"[dict get $args banner]\">"
    }


    I hope Tcllib httpd maintainer can clarify/fix/update this package if my information is useful.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Gerald Lester@21:1/5 to Danilo Chang on Sat Nov 11 09:34:46 2023
    On 11/11/23 06:41, Danilo Chang wrote:
    I notice tcllib httpd package has some issues (source code and document),
    so I test tcllib httpd v4.3.5 to check its status.

    Then I create 2 tickets for httpd package, c0e70192dd45ea7b26cc8470a4025fe9e8b70d16 - httpd ::httpd::content.file method content issue
    9d1f4444f144619857bd281beb24199b005d2edc - httpd Minimal Example not work

    When I check the tickets list, I find below cases also about httpd Example: 85d8548e0acf775c153f381cb4642d89ba1a41f3 79c916b904bb11c028feefd9251f2fa18b637b08 0924679869f8a16ee82659fcca25b07d612d2ab7 1b43369dbc9e4ab14533b5a40f0ac41976f308fc

    Tcllib examples/httpd/httpd.tcl is OK,
    but Tcler's wiki and tcllib httpd document example both not work.


    1. Tcler's wiki example

    It maybe the version upgrade issue.
    (It is about issue 79c916b904bb11c028feefd9251f2fa18b637b08)

    The solution is to remove the "HTTPD start" this line.

    The reason is ::httpd::server constructor finally call `start` method,
    so you don't need to call it again.
    This is why you will get "couldn't open socket: address already in use" message.

    I ref other examples and update the example code in Tcler's wiki,
    the example works in my environment for httpd v4.3.5.


    2. Tcllib httpd document Minimal Example

    It maybe the version upgrade issue.
    (It is about issues
    85d8548e0acf775c153f381cb4642d89ba1a41f3, 0924679869f8a16ee82659fcca25b07d612d2ab7, 1b43369dbc9e4ab14533b5a40f0ac41976f308fc, 9d1f4444f144619857bd281beb24199b005d2edc)

    Tcllib httpd document Minimal Example is terrible for new user.
    I find below problems:
    1) Class httpd::server::dispatch for plugin dispatch does not exist
    2) ::reply.hello results in error (should use clay::define to implement content)
    3) uri add behavior is wrong, should use {content reply.hello} to replace reply.hello

    So the Minimal Example in tcllib httpd document should change to -

    clay::define ::reply.hello {
    method content {} {
    my puts "<HTML><HEAD><TITLE>IRM Dispatch Server</TITLE></HEAD><BODY>"
    my puts "<h1>Hello World!</h1>"
    my puts </BODY></HTML>
    }
    }
    ::httpd::server create HTTPD port 8015 myaddr 127.0.0.1 doc_root ~/htdocs HTTPD plugin dispatch ::httpd::plugin.dict_dispatch
    HTTPD uri add * /hello [list mixin {content reply.hello}]


    3. httpd ::httpd::content.file method content issue

    (It is about issue c0e70192dd45ea7b26cc8470a4025fe9e8b70d16)

    I try to create a server to serve static files for myself.
    If the URL is
    http://localhost:8015/Language/index.html

    Then httpd will try to find
    http://localhost:8015/Language/index.html/

    Then results in "Listing contents of /Language/index.html/"
    The behavior is wrong, because I request to get index.html file content.

    If you have second level directory and try to get index.html,
    it is not as you expect in current httpd code base.

    After check the source code, I think because below conditions:

    if {[file isdirectory $local_file] || [file tail $local_file] in {index index.html index.tml index.md}} {

    The condition [file tail $local_file] in {index index.html index.tml index.md} results in error case.
    If it is a feature for httpd, for what? I feel the condition is strange and result in errors.
    So I think it needs to clarify. And if it is not a feature and does not influence something, it is good to remove the second condition.


    4. Tcllib/httpd: Directory listing & error pages try to load /images/etoyoc-banner.jpg

    (It is about issue 7987932aaae1de26db7c2dcf82b6fba9b76e7e3b)

    When producing a directory listing with Tcllib/httpd,
    the generated HTML code tries to display the (non-existent & unconfigurable) image '/images/etoyoc-banner.jpg'.

    It is ::httpd::reply method html_header behavior, below is the code.

    if {[dict exists $args banner]} {
    append result "<img src=\"[dict get $args banner]\">"
    } else {
    append result {<img src="/images/etoyoc-banner.jpg">}
    }

    I suggest change to below code:

    if {[dict exists $args banner]} {
    append result "<img src=\"[dict get $args banner]\">"
    }


    I hope Tcllib httpd maintainer can clarify/fix/update this package if my information is useful.

    Feel free to update the Wiki and to submit fixes (patched) to TclLib.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)