| 934 | } |
| 935 | |
| 936 | func sendFileContentLength(path string, cfg SendFile) (int64, error) { |
| 937 | if cfg.FS != nil { |
| 938 | cleanPath := pathpkg.Clean(utils.TrimLeft(path, '/')) |
| 939 | if cleanPath == "." { |
| 940 | cleanPath = "" |
| 941 | } |
| 942 | info, err := fs.Stat(cfg.FS, cleanPath) |
| 943 | if err != nil { |
| 944 | return 0, fmt.Errorf("stat %q: %w", cleanPath, err) |
| 945 | } |
| 946 | return info.Size(), nil |
| 947 | } |
| 948 | |
| 949 | info, err := os.Stat(filepath.FromSlash(path)) |
| 950 | if err != nil { |
| 951 | return 0, fmt.Errorf("stat %q: %w", path, err) |
| 952 | } |
| 953 | |
| 954 | return info.Size(), nil |
| 955 | } |
| 956 | |
| 957 | // SendStatus sets the HTTP status code and if the response body is empty, |
| 958 | // it sets the correct status message in the body. |