upload a file to local host returns 301 #391

Closed
opened 2026-01-19 18:30:09 +00:00 by michael · 6 comments
Owner

Originally created by @oren on GitHub.

I am installing the app using docker on my laptop. I get 301 when trying to upload a file.
curl -v --upload-file ./hello.txt http://localhost:8080/hello.txt

* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> PUT /hello.txt HTTP/1.1
> User-Agent: curl/7.37.1
> Host: localhost:8080
> Accept: */*
> Content-Length: 10
> Expect: 100-continue
> 
< HTTP/1.1 301 Moved Permanently
< Location: https://transfer.sh/hello.txt
* Server Transfer.sh HTTP Server 1.0 is not blacklisted
< Server: Transfer.sh HTTP Server 1.0
< X-Made-With: <3 by DutchCoders
< X-Served-By: Proudly served by DutchCoders
< Date: Mon, 08 Dec 2014 21:33:32 GMT
< Content-Length: 0
< Content-Type: text/plain; charset=utf-8
* HTTP error before end of send, stop sending
Originally created by @oren on GitHub. I am installing the app using docker on my laptop. I get 301 when trying to upload a file. curl -v --upload-file ./hello.txt http://localhost:8080/hello.txt ``` * Hostname was NOT found in DNS cache * Trying 127.0.0.1... * Connected to localhost (127.0.0.1) port 8080 (#0) > PUT /hello.txt HTTP/1.1 > User-Agent: curl/7.37.1 > Host: localhost:8080 > Accept: */* > Content-Length: 10 > Expect: 100-continue > < HTTP/1.1 301 Moved Permanently < Location: https://transfer.sh/hello.txt * Server Transfer.sh HTTP Server 1.0 is not blacklisted < Server: Transfer.sh HTTP Server 1.0 < X-Made-With: <3 by DutchCoders < X-Served-By: Proudly served by DutchCoders < Date: Mon, 08 Dec 2014 21:33:32 GMT < Content-Length: 0 < Content-Type: text/plain; charset=utf-8 * HTTP error before end of send, stop sending ```
Author
Owner

@nl5887 commented on GitHub:

Currently there is a redirect checking if the connection is secure. If not then it will redirect to https://transfer.sh/. Will work on a solution to disable the check.

@nl5887 commented on GitHub: Currently there is a redirect checking if the connection is secure. If not then it will redirect to https://transfer.sh/. Will work on a solution to disable the check.
Author
Owner

@nl5887 commented on GitHub:

In the mean time, you can workaround this issue by removing the RedirectHandler in main.go, by changing:

Handler: handlers.PanicHandler(LoveHandler(RedirectHandler(handlers.LogHandler(r, handlers.NewLogOptions(log.Printf, "_default_")))), nil),

to

Handler: handlers.PanicHandler(LoveHandler(handlers.LogHandler(r, handlers.NewLogOptions(log.Printf, "_default_"))), nil),
@nl5887 commented on GitHub: In the mean time, you can workaround this issue by removing the RedirectHandler in main.go, by changing: ``` Handler: handlers.PanicHandler(LoveHandler(RedirectHandler(handlers.LogHandler(r, handlers.NewLogOptions(log.Printf, "_default_")))), nil), ``` to ``` Handler: handlers.PanicHandler(LoveHandler(handlers.LogHandler(r, handlers.NewLogOptions(log.Printf, "_default_"))), nil), ```
Author
Owner

@jasonyost commented on GitHub:

Just ran into this issue myself, the code for the redirect handler is looking for a host of 127.0.0.1 in handlers.go

func RedirectHandler(h http.Handler) http.HandlerFunc {
    return func(w http.ResponseWriter, r *http.Request) {
        if r.URL.Path == "/health.html" {
        } else if ipAddrFromRemoteAddr(r.Host) == "127.0.0.1" {
        } else if strings.HasSuffix(ipAddrFromRemoteAddr(r.Host), ".elasticbeanstalk.com") {
        } else if ipAddrFromRemoteAddr(r.Host) == "jxm5d6emw5rknovg.onion" {
        } else if ipAddrFromRemoteAddr(r.Host) == "transfer.sh" {
            if r.Header.Get("X-Forwarded-Proto") != "https" && r.Method == "GET" {
                http.Redirect(w, r, "https://transfer.sh"+r.RequestURI, 301)
                return
            }
        } else if ipAddrFromRemoteAddr(r.Host) != "transfer.sh" {
            http.Redirect(w, r, "https://transfer.sh"+r.RequestURI, 301)
            return
        }

        h.ServeHTTP(w, r)
    }
}

Changing my curl command to curl -v --upload-file ./hello.txt http://127.0.0.1:8080/hello.txt resolves the issue for me

@jasonyost commented on GitHub: Just ran into this issue myself, the code for the redirect handler is looking for a host of `127.0.0.1` in handlers.go ``` go func RedirectHandler(h http.Handler) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { if r.URL.Path == "/health.html" { } else if ipAddrFromRemoteAddr(r.Host) == "127.0.0.1" { } else if strings.HasSuffix(ipAddrFromRemoteAddr(r.Host), ".elasticbeanstalk.com") { } else if ipAddrFromRemoteAddr(r.Host) == "jxm5d6emw5rknovg.onion" { } else if ipAddrFromRemoteAddr(r.Host) == "transfer.sh" { if r.Header.Get("X-Forwarded-Proto") != "https" && r.Method == "GET" { http.Redirect(w, r, "https://transfer.sh"+r.RequestURI, 301) return } } else if ipAddrFromRemoteAddr(r.Host) != "transfer.sh" { http.Redirect(w, r, "https://transfer.sh"+r.RequestURI, 301) return } h.ServeHTTP(w, r) } } ``` Changing my curl command to `curl -v --upload-file ./hello.txt http://127.0.0.1:8080/hello.txt` resolves the issue for me
Author
Owner

@mapio commented on GitHub:

I did it like https://github.com/mapio/transfer.sh/blob/master/transfersh-server/main.go#L172 and it now works!

[But I had to clean the browser caches to force it to forget the old "moved permanently"… dunno why!]

@mapio commented on GitHub: I did it like https://github.com/mapio/transfer.sh/blob/master/transfersh-server/main.go#L172 and it now works! [But I had to clean the browser caches to force it to forget the old "moved permanently"… dunno why!]
Author
Owner

@mapio commented on GitHub:

This actually happens not only for an upload, but even accessing to the homepage!

$ curl -D-  http://localhost:8080/
HTTP/1.1 301 Moved Permanently
Location: https://transfer.sh/
Server: Transfer.sh HTTP Server 1.0
X-Made-With: <3 by DutchCoders
X-Served-By: Proudly served by DutchCoders
Date: Sun, 25 Jan 2015 23:53:19 GMT
Content-Length: 55
Content-Type: text/html; charset=utf-8

<a href="https://transfer.sh/">Moved Permanently</a>.

I hope you'll fix it because I'd like to run this on a private network!

@mapio commented on GitHub: This actually happens not only for an upload, but even accessing to the homepage! ``` $ curl -D- http://localhost:8080/ HTTP/1.1 301 Moved Permanently Location: https://transfer.sh/ Server: Transfer.sh HTTP Server 1.0 X-Made-With: <3 by DutchCoders X-Served-By: Proudly served by DutchCoders Date: Sun, 25 Jan 2015 23:53:19 GMT Content-Length: 55 Content-Type: text/html; charset=utf-8 <a href="https://transfer.sh/">Moved Permanently</a>. ``` I hope you'll fix it because I'd like to run this on a private network!
Author
Owner

@acepsaepudin commented on GitHub:

thanks @jasonyost +1

@acepsaepudin commented on GitHub: thanks @jasonyost +1
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dutchcoders/transfer.sh#391