dutchcoders/transfer.sh · error

Internal server error.

Error message

Internal server error.

What it means

After building a zip.FileHeader, zipHandler calls zw.CreateHeader(header) to add an entry to the streaming zip. On failure the server responds with HTTP 500 'Internal server error.'. CreateHeader only fails in narrow cases — the underlying writer has already errored, or the header is invalid.

Source

Thrown at server/handlers.go:1015

			}

			s.logger.Printf("%s", err.Error())
			http.Error(w, "Could not retrieve file.", http.StatusInternalServerError)
			return
		}

		header := &zip.FileHeader{
			Name:   strings.Split(key, "/")[1],
			Method: zip.Store,

			Modified: time.Now().UTC(),
		}

		fw, err := zw.CreateHeader(header)

		if err != nil {
			s.logger.Printf("%s", err.Error())
			http.Error(w, "Internal server error.", http.StatusInternalServerError)
			return
		}

		if _, err = io.Copy(fw, reader); err != nil {
			s.logger.Printf("%s", err.Error())
			http.Error(w, "Internal server error.", http.StatusInternalServerError)
			return
		}
	}

	if err := zw.Close(); err != nil {
		s.logger.Printf("%s", err.Error())
		http.Error(w, "Internal server error.", http.StatusInternalServerError)
		return
	}
}

func (s *Server) tarGzHandler(w http.ResponseWriter, r *http.Request) {

View on GitHub (pinned to c37bfd9579)

Solutions

  1. Retry the download; if the client disconnected, this is expected and harmless — verify client connectivity.
  2. Check the log line emitted with the 500 to distinguish header-name errors from write errors.
  3. Sanitize/validate the entry name derived from the storage key before building the header.
  4. Ensure no buffering middleware truncates the streamed response for large archives.

Example fix

// before
Name: strings.Split(key, "/")[1],
// after
parts := strings.Split(key, "/")
name := "file"
if len(parts) > 1 && parts[1] != "" {
    name = path.Base(parts[1])
}
header := &zip.FileHeader{Name: name, Method: zip.Store}
Defensive patterns

Strategy: try-catch

Validate before calling

// Validate the entry name before requesting the archive:
name := path.Base(strings.SplitN(key, "/", 2)[1])
if name == "" || strings.ContainsAny(name, "\\\x00") {
    // invalid zip entry name; fix the key naming scheme
}

Try / catch

// 500 during streaming usually means client disconnect; check logs to distinguish
// header errors (fix name) from write errors (client/connection issue)

Prevention

When it happens

Trigger: zw.CreateHeader returns an error: the underlying HTTP response writer failed (client disconnected, connection reset), or the FileHeader name is invalid/empty (e.g. strings.Split(key, "/")[1] yielded an empty or malformed name).

Common situations: Client aborted the download mid-stream so ResponseWriter writes fail; filename derived from the storage key is empty or contains invalid zip path characters; zip64 limits approached for very large archives.

Understand the failure class

Related errors


AI-assisted analysis of dutchcoders/transfer.sh@c37bfd9579 (2026-09-05). Data as JSON: /api/errors/9452e09a6d00feba. Report an issue: GitHub.