Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Response template doesn't get returned on successful upload #12

Closed
etherwvlf opened this issue May 6, 2023 · 7 comments
Closed

Response template doesn't get returned on successful upload #12

etherwvlf opened this issue May 6, 2023 · 7 comments

Comments

@etherwvlf
Copy link

Everything fine and dandy. Building with xcaddy and go versions:

v0.3.3 h1:0TdKXGl1u6Fc0Duc4qG0zu/aMyU/cTYgoXrvTkMeSnY=
go version go1.20.4 linux/amd64

I think the response template doesn't seem to be returned on successful upload when compared to the previous build.
This is now:

user@654567547:/test$ curl -kv --form [email protected] http://localhost:9000/upload-template.htm
*   Trying 127.0.0.1:9000...
* Connected to localhost (127.0.0.1) port 9000 (#0)
> POST /upload-template.htm HTTP/1.1
> Host: localhost:9000
> User-Agent: curl/7.88.1
> Accept: */*
> Content-Length: 19963043
> Content-Type: multipart/form-data; boundary=------------------------d84106d9eac5a586
> Expect: 100-continue
> 
< HTTP/1.1 100 Continue
* We are completely uploaded and fine
< HTTP/1.1 201 Created
< Server: Caddy
< Date: Sat, 06 May 2023 21:28:04 GMT
< Content-Length: 0
< 
* Connection #0 to host localhost left intact

This was before:

user@654567547:/test$ curl -kv --form [email protected] http://localhost:9000/upload-template.htm
*   Trying 127.0.0.1:9000...
* Connected to localhost (127.0.0.1) port 9000 (#0)
> POST /upload-template.htm HTTP/1.1
> Host: localhost:9000
> User-Agent: curl/7.87.0
> Accept: */*
> Content-Length: 6607691
> Content-Type: multipart/form-data; boundary=------------------------15c7d37773cc1a35
> Expect: 100-continue
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 100 Continue
* We are completely uploaded and fine
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Content-Length: 197
< Content-Type: text/plain; charset=utf-8
< Server: Caddy
< Date: Wed, 22 Feb 2023 09:58:58 GMT
< 


http.request.uri.path: /upload-resp-template.txt

http.request.uuid c92559ee-4533-417a-831e-825627512927
http.request.host localhost

http.upload.filename: chm.pdf
http.upload.filesize: 6607499

* Connection #0 to host localhost left intact
@git001
Copy link
Owner

git001 commented May 7, 2023

Thank you. I will take a look. Please can you share your config so that I can compare it then with my

@etherwvlf
Copy link
Author

Ooops, my bad...
Here goes:

{
	http_port 9000
	https_port 9001
	admin off
	order upload before file_server
}

localhost:9000 {
	root .

	file_server browse
	templates

	@mypost method POST
	upload @mypost {
		dest_dir .
		max_filesize 15G
		max_form_buffer 100MB
		file_field_name myFile
		response_template upload-resp-template.txt
	}

	log {
		output file access.log
	}
}

@JackBailey
Copy link

Same issue, my config:

@cdn host cdn.example.com
handle @cdn {
        templates
        root * /sites/cdn
        file_server

        @cdn-upload {
                path /upload
                method POST
                header Token "REDACTED"
        }
        upload @cdn-upload {
                dest_dir /sites/cdn/uploads
                max_form_buffer 1G
                file_field_name file
                response_template upload-resp.txt
        }
}

@git001
Copy link
Owner

git001 commented May 9, 2023

I think the commit ca7ef14 which return's nil could be the issue as the template is evaluated by the file_sever.

No blaming to @jmshrv as I should have done this.

This is the snipplet.

        return next.ServeHTTP(w, r)
	w.WriteHeader(http.StatusCreated)
	return nil

I'm digging deeper into the topic.

git001 added a commit that referenced this issue May 9, 2023
To fix the gh issue #12 is it necessary to change the HTTP
Method so that the folling handler (file_server) is able to
read the response template.

I'm not sure if this is the best method to fix the issue but
it's an working method.
@git001
Copy link
Owner

git001 commented May 9, 2023

@etherwvlf , @JackBailey please can you try the new commit if it solves the issue.

@JackBailey
Copy link

Yep, fixes it for me

@etherwvlf
Copy link
Author

Works flawlessly for me too.
Thank you, I am closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants