# Author:       Li Junhao   l@x-cmd.com     # xrc
# shellcheck    shell=sh    disable=SC2039,SC3043
___x_cmd_http_resp() {
    param:subcmd ______x_cmd_http_resp                              \
        header              "Show header of latest response"        \
        body                "Show body of latest response"          \
        body_filepath       "show body filepath of latest response" \
        header_filepath     "show header filepath of latest response" \
        status              "show status of latest response"        \
        status_filepath     "show status filepath of latest response"
    param:subcmd:try
    param:run

    ___x_cmd_http_resp _param_help_doc
    return 1
}

______x_cmd_http_resp_header(){
    param:void
    if [ -z "$1" ]; then
        ___x_cmd_cmds_cat "$(______x_cmd_http_resp_header_filepath)"
    else
        local filepath
        filepath="$(______x_cmd_http_resp_header_filepath)"
        local filter="${1:?provide filter}"
        local A
        A="$(command grep "$filter:" "$filepath")"
        A="${A##"$filter": }"
        printf "%s" "${A%"${A##*[![:space:]]}"}"
    fi
}

______x_cmd_http_resp_header_filepath(){
    param:void
    printf "%s" "${TMPDIR%/}/x-cmd-x-bash-std-http-header.${O:-___X_BASH_HTTP__HTTP_DEFAULT}"
}

______x_cmd_http_resp_body(){
    param:void
    ___x_cmd_cmds_cat "$(______x_cmd_http_resp_body_filepath)"
}

______x_cmd_http_resp_body_filepath(){
    param:void
    printf "%s" "${TMPDIR%/}/x-cmd-x-bash-std-http-body.${O:-___X_BASH_HTTP__HTTP_DEFAULT}"
}

______x_cmd_http_resp_status(){
    param:void
    ___x_cmd_cmds_cat "$(______x_cmd_http_resp_status_filepath)"
}

______x_cmd_http_resp_status_filepath(){
    param:void
    printf "%s" "${TMPDIR%/}/x-cmd-x-bash-std-http-status.${O:-___X_BASH_HTTP__HTTP_DEFAULT}"
}