`resources.Get` and `resources.GetRemote` return `nil` if the resource is not found.
+{{< new-in "0.110.0" >}} You can get information about the HTTP Response using `.Data` in the returned `Resource`. This is especially useful for HEAD request without any body. The Data object contains:
+
+StatusCode
+: The HTTP status code, e.g. 200
+Status
+: The HTTP status text, e.g. "200 OK"
+TransferEncoding
+: The transfer encoding, e.g. "chunked"
+ContentLength
+: The content length, e.g. 1234
+ContentType
+: The content type, e.g. "text/html"
+
+
## Copy a Resource
{{< new-in "0.100.0" >}}
Fs afero.Fs
+ Data map[string]any
+
// Set when its known up front, else it's resolved from the target filename.
MediaType media.Type
{{ 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 }}
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:[]]",
+ )
}
}
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
sourceFilename,
baseFilename,
mediaType,
+ nil,
)
}
osFileInfo os.FileInfo,
sourceFilename,
baseFilename string,
- mediaType media.Type) *genericResource {
+ mediaType media.Type,
+ data map[string]any,
+) *genericResource {
if osFileInfo != nil && osFileInfo.IsDir() {
panic(fmt.Sprintf("dirs not supported resource types: %v", osFileInfo))
}
name: baseFilename,
title: baseFilename,
resourceContent: &resourceContent{},
+ data: data,
}
return g
fi,
sourceFilename,
fd.RelTargetFilename,
- mimeType)
+ mimeType,
+ fd.Data)
if mimeType.MainType == "image" {
imgFormat, ok := images.ImageFormatFromMediaSubType(mimeType.SubType)