2025-11-13 19:38:23 +00:00
|
|
|
package main
|
|
|
|
|
|
2025-11-14 11:12:15 +00:00
|
|
|
import (
|
|
|
|
|
"log"
|
feat: Add configurable timeouts for HTTP requests
This commit introduces configurable timeouts for HTTP requests made by the `collect` commands.
Key changes:
- Created a new `pkg/httpclient` package with a `NewClient` function that returns an `http.Client` with configurable timeouts for total, connect, TLS, and header stages.
- Added `--timeout`, `--connect-timeout`, `--tls-timeout`, and `--header-timeout` persistent flags to the `collect` command, making them available to all its subcommands.
- Refactored the `pkg/website`, `pkg/pwa`, and `pkg/github` packages to accept and use a custom `http.Client`, allowing the timeout configurations to be injected.
- Updated the `collect website`, `collect pwa`, and `collect github repos` commands to create a configured HTTP client based on the new flags and pass it to the respective packages.
- Added unit tests for the `pkg/httpclient` package to verify correct timeout configuration.
- Fixed all test and build failures that resulted from the refactoring.
- Addressed an unrelated build failure by creating a placeholder file (`pkg/player/frontend/demo-track.smsg`).
This work addresses the initial requirement for configurable timeouts via command-line flags. Further work is needed to implement per-domain overrides from a configuration file and idle timeouts for large file downloads.
Co-authored-by: Snider <631881+Snider@users.noreply.github.com>
2026-02-02 00:58:11 +00:00
|
|
|
"net/http"
|
2025-11-14 11:12:15 +00:00
|
|
|
"os"
|
|
|
|
|
|
|
|
|
|
"github.com/Snider/Borg/pkg/website"
|
|
|
|
|
)
|
2025-11-13 19:38:23 +00:00
|
|
|
|
|
|
|
|
func main() {
|
2025-11-14 11:12:15 +00:00
|
|
|
log.Println("Collecting website...")
|
|
|
|
|
|
|
|
|
|
// Download and package the website.
|
feat: Add configurable timeouts for HTTP requests
This commit introduces configurable timeouts for HTTP requests made by the `collect` commands.
Key changes:
- Created a new `pkg/httpclient` package with a `NewClient` function that returns an `http.Client` with configurable timeouts for total, connect, TLS, and header stages.
- Added `--timeout`, `--connect-timeout`, `--tls-timeout`, and `--header-timeout` persistent flags to the `collect` command, making them available to all its subcommands.
- Refactored the `pkg/website`, `pkg/pwa`, and `pkg/github` packages to accept and use a custom `http.Client`, allowing the timeout configurations to be injected.
- Updated the `collect website`, `collect pwa`, and `collect github repos` commands to create a configured HTTP client based on the new flags and pass it to the respective packages.
- Added unit tests for the `pkg/httpclient` package to verify correct timeout configuration.
- Fixed all test and build failures that resulted from the refactoring.
- Addressed an unrelated build failure by creating a placeholder file (`pkg/player/frontend/demo-track.smsg`).
This work addresses the initial requirement for configurable timeouts via command-line flags. Further work is needed to implement per-domain overrides from a configuration file and idle timeouts for large file downloads.
Co-authored-by: Snider <631881+Snider@users.noreply.github.com>
2026-02-02 00:58:11 +00:00
|
|
|
dn, err := website.DownloadAndPackageWebsite("https://example.com", 2, nil, http.DefaultClient)
|
2025-11-14 11:12:15 +00:00
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("Failed to collect website: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Serialize the DataNode to a tarball.
|
|
|
|
|
tarball, err := dn.ToTar()
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("Failed to serialize datanode to tar: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Write the tarball to a file.
|
|
|
|
|
err = os.WriteFile("website.dat", tarball, 0644)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("Failed to write datanode file: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.Println("Successfully created website.dat")
|
2025-11-13 19:38:23 +00:00
|
|
|
}
|