Add fill HTTP Response info into .Data in resources.GetRemote

See #10604
This commit is contained in:
Bjørn Erik Pedersen
2023-01-16 12:44:39 +01:00
parent f13531e608
commit 6a579ebac3
5 changed files with 30 additions and 4 deletions

View File

@@ -35,7 +35,7 @@ func TestGetResourceHead(t *testing.T) {
{{ with .Err }}
{{ errorf "Unable to get remote resource: %s" . }}
{{ else }}
Head Content: {{ .Content }}.
Head Content: {{ .Content }}. Head Data: {{ .Data }}
{{ end }}
{{ else }}
{{ errorf "Unable to get remote resource: %s" $url }}
@@ -51,6 +51,9 @@ func TestGetResourceHead(t *testing.T) {
b.Build()
b.AssertFileContent("public/index.html", "Head Content: .")
b.AssertFileContent("public/index.html",
"Head Content: .",
"Head Data: map[ContentLength:18210 ContentType:image/png Status:200 OK StatusCode:200 TransferEncoding:[]]",
)
}

View File

@@ -207,10 +207,12 @@ func (c *Client) FromRemote(uri string, optionsm map[string]any) (resource.Resou
}
resourceID = filename[:len(filename)-len(path.Ext(filename))] + "_" + resourceID + mediaType.FirstSuffix.FullSuffix
data := responseToData(res, false)
return c.rs.New(
resources.ResourceSourceDescriptor{
MediaType: mediaType,
Data: data,
LazyPublish: true,
OpenReadSeekCloser: func() (hugio.ReadSeekCloser, error) {
return hugio.NewReadSeekerNoOpCloser(bytes.NewReader(body)), nil