mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
resources: Add timeout to the HTTP request in Get
Workaround for https://github.com/golang/go/issues/49366
This commit is contained in:
parent
94f149b21e
commit
93572e5318
4 changed files with 12 additions and 3 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,6 +1,7 @@
|
||||||
/hugo
|
/hugo
|
||||||
docs/public*
|
docs/public*
|
||||||
/.idea
|
/.idea
|
||||||
|
.vscode/*
|
||||||
hugo.exe
|
hugo.exe
|
||||||
*.test
|
*.test
|
||||||
*.prof
|
*.prof
|
||||||
|
|
2
cache/filecache/filecache_test.go
vendored
2
cache/filecache/filecache_test.go
vendored
|
@ -276,7 +276,7 @@ func TestFileCacheReadOrCreateErrorInRead(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cache := NewCache(afero.NewMemMapFs(), 100*time.Hour, "")
|
cache := NewCache(afero.NewMemMapFs(), 100*time.Hour, 0, "")
|
||||||
|
|
||||||
const id = "a32"
|
const id = "a32"
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ package create
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -180,6 +181,14 @@ func (c *Client) FromRemote(uri string, options map[string]interface{}) (resourc
|
||||||
}
|
}
|
||||||
addUserProvidedHeaders(headers, req)
|
addUserProvidedHeaders(headers, req)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Workaround for https://github.com/golang/go/issues/49366
|
||||||
|
// This is the entire lifetime of the request.
|
||||||
|
ctx, cancel := context.WithTimeout(req.Context(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
req = req.WithContext(ctx)
|
||||||
|
|
||||||
res, err := c.httpClient.Do(req)
|
res, err := c.httpClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -34,7 +34,6 @@ import (
|
||||||
"github.com/gohugoio/hugo/hugofs"
|
"github.com/gohugoio/hugo/hugofs"
|
||||||
"github.com/gohugoio/hugo/langs"
|
"github.com/gohugoio/hugo/langs"
|
||||||
"github.com/spf13/afero"
|
"github.com/spf13/afero"
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestScpGetLocal(t *testing.T) {
|
func TestScpGetLocal(t *testing.T) {
|
||||||
|
@ -87,7 +86,7 @@ func TestScpGetRemote(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
c := qt.New(t)
|
c := qt.New(t)
|
||||||
fs := new(afero.MemMapFs)
|
fs := new(afero.MemMapFs)
|
||||||
cache := filecache.NewCache(fs, 100, "")
|
cache := filecache.NewCache(fs, 100, 0, "")
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
path string
|
path string
|
||||||
|
|
Loading…
Reference in a new issue