func serveLocalPackage()

in packages/http.go [65:92]


func serveLocalPackage(logger *zap.Logger, w http.ResponseWriter, r *http.Request, p *Package, packagePath string) {
	span, _ := apm.StartSpan(r.Context(), "ServePackage", "app")
	defer span.End()

	logger = logger.With(zap.String("file.name", packagePath))

	f, err := os.Stat(packagePath)
	if err != nil {
		logger.Error("stat package path failed", zap.Error(err))
		http.Error(w, "internal server error", http.StatusInternalServerError)
		return
	}

	if f.IsDir() {
		w.Header().Set("Content-Type", "application/zip")
		err = archiver.ArchivePackage(w, archiver.PackageProperties{
			Name:    p.Name,
			Version: p.Version,
			Path:    packagePath,
		})
		if err != nil {
			logger.Error("archiving package path failed", zap.Error(err))
		}
		return
	}

	http.ServeFile(w, r, packagePath)
}