diff options
author | Jordan <me@jordan.im> | 2021-07-23 13:57:39 -0700 |
---|---|---|
committer | Jordan <me@jordan.im> | 2021-07-23 13:57:39 -0700 |
commit | 2120238760d974f2b0f5cc99faa7ecaf23989bf2 (patch) | |
tree | 678dfdd46c3b9746fda3adcbdaf9e33b46dface0 | |
parent | a137591f04e28d387b3d76408d5e1d8238344720 (diff) | |
download | crane-2120238760d974f2b0f5cc99faa7ecaf23989bf2.tar.gz crane-2120238760d974f2b0f5cc99faa7ecaf23989bf2.zip |
timeout outbound HTTP request after 25s
-rw-r--r-- | crane.go | 14 |
1 files changed, 10 insertions, 4 deletions
@@ -18,11 +18,15 @@ import ( "path/filepath" "strings" "sync" + "time" "golang.org/x/net/publicsuffix" ) -const MAX_SIZE int64 = 50000000 // max incoming HTTP request body size (50MB) +const ( + TIMEOUT time.Duration = 25 // seconds to wait for an outbound HTTP request to complete + MAX_SIZE int64 = 50000000 // max incoming HTTP request body size (50MB) +) var ( client *http.Client @@ -431,8 +435,7 @@ func (papers *Papers) MovePaper(paper string, category string) error { papers.Lock() paperDest := filepath.Join(filepath.Join(papers.Path, category), papers.List[prevCategory][paper].PaperName+".pdf") - if err := os.Rename(papers.List[prevCategory][paper].PaperPath, paperDest); - err != nil { + if err := os.Rename(papers.List[prevCategory][paper].PaperPath, paperDest); err != nil { return err } @@ -604,7 +607,10 @@ func main() { } return conn, err } - client = &http.Client{Jar: cookies} + client = &http.Client{ + Jar: cookies, + Timeout: TIMEOUT * time.Second, + } var papers Papers papers.List = make(map[string]map[string]*Paper) |