caddy-s3-proxy icon indicating copy to clipboard operation
caddy-s3-proxy copied to clipboard

default_listing BrowseTemplate causing 500 response

Open BrianFanning opened this issue 4 years ago • 2 comments

This was mentioned in issue #50, but the issue was closed by the reporter. I'm having the same issue. If you are using the default BrowseTemplate, a 500 error is returned to the user. Error logs in Caddy:

{
	"level": "error",
	"ts": 1643739892.6739354,
	"logger": "http.log.error",
	"msg": "template: default_listing:5:26: executing \"default_listing\" at <.PageObj>: can't evaluate field PageObj in type caddys3proxy.PageObj",
	"request": {
		"remote_addr": "10.113.133.2:46012",
		"proto": "HTTP/1.1",
		"method": "GET",
		"host": "s3proxy.redacted",
		"uri": "/?max=20",
		"headers": {
			"X-Request-Id": ["913cd8227b352f76365baa7c2c255f"],
			"X-Real-Ip": ["10.167.1.129"],
			"X-Forwarded-Host": ["s3proxy.redacted"],
			"User-Agent": ["curl/7.80.0"],
			"Content-Type": ["text/html"],
			"X-Forwarded-For": ["10.17.1.19"],
			"X-Forwarded-Port": ["80"],
			"X-Forwarded-Proto": ["http"],
			"X-Scheme": ["http"],
			"Accept": ["*/*"]
		}
	},
	"duration": 1.04688346,
	"status": 500,
	"err_id": "eqh8tru7r",
	"err_trace": "caddy-s3-proxy.convertToCaddyError (errors.go:118)"
}

BrianFanning avatar Feb 01 '22 18:02 BrianFanning

@BrianFanning I reproduced the exact error you reported while attempting to use the browse feature to list an AWS S3 bucket. I noticed your PR #53, however when I built your branch for my s3caddy plugin and retried the request I was still unable to see the browse feature working.

And still see: http.log.error template: default_listing:5:26: executing "default_listing" at <.PageObj>: can't evaluate field PageObj in type caddys3proxy.PageObj

Were you able to get this working on your builds?

porkcharsui avatar Apr 29 '22 05:04 porkcharsui

Thank you for the great implementation.

I think this is a bug in the default template. The following part seems to be wrong. https://github.com/lindenlab/caddy-s3-proxy/blob/0c6e6cdacab0d8bb2796a8cca5e65ab00b680483/browse.go#L146

The correct is: .PageObj -> .Items

I built @BrianFanning 's branch. And I wrote following template file and load it, browse feature works.

<!DOCTYPE html>
<html>
        <body>
                <ul>
                {{- range .Items }}
                <li>
                {{- if .IsDir}}
                <a href="{{html .Url}}">{{html .Name}}</a>
                {{- else}}
                <a href="{{html .Url}}">{{html .Name}}</a> Size: {{html .Size}} Last Modified: {{html .LastModified}}
                {{- end}}
                </li>
                {{- end }}
                </ul>
		<p>number of items: {{ .Count }}</p>
		{{- if .MoreLink }}
		<a href="{{ html .MoreLink }}">more...</a>
		{{- end }}
        </body>
</html>

etsxxx avatar Aug 22 '22 02:08 etsxxx