<commit_before>package main

import (
	"fmt"
	"net/http"
	"strings"
	"time"

	"github.com/pachyderm/pachyderm/src/client"
)

const timeFormat = "Mon, 02 Jan 2006 15:04:05 GMT"

// Serve runs an HTTP server with an S3-like API for PFS
func Serve(pc *client.APIClient, port uint16) {
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		parts := strings.SplitN(r.URL.Path, "/", 3)

		if len(parts) < 3 {
			http.Error(w, "Invalid path", 404)
			return
		}

		repo, file := parts[1], parts[2]

		fileInfo, err := pc.InspectFile(repo, "master", file)

		if err != nil {
			code := 500

			if strings.Contains(err.Error(), "not found in repo") {
				code = 404
			}

			http.Error(w, fmt.Sprintf("%v", err), code)
			return
		}

		committed := fileInfo.Committed
		timestamp := time.Unix(committed.GetSeconds(), int64(committed.GetNanos()))
		w.Header().Set("Last-Modified", timestamp.UTC().Format(timeFormat))

		if err := pc.GetFile(repo, "master", file, 0, 0, w); err != nil {
			http.Error(w, fmt.Sprintf("%v", err), 500)
			return
		}
	})

	http.ListenAndServe(fmt.Sprintf(":%d", port), nil)
}<commit_msg>Use `ServeContent` to support range queries, etags, etc.<commit_after>package main

import (
	"fmt"
	"net/http"
	"strings"
	"time"

	"github.com/pachyderm/pachyderm/src/client"
)

const timeFormat = "Mon, 02 Jan 2006 15:04:05 GMT"

// Serve runs an HTTP server with an S3-like API for PFS
func Serve(pc *client.APIClient, port uint16) {
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		parts := strings.SplitN(r.URL.Path, "/", 3)

		if len(parts) < 3 {
			http.Error(w, "Invalid path", 404)
			return
		}

		repo, file := parts[1], parts[2]

		fileInfo, err := pc.InspectFile(repo, "master", file)
		if err != nil {
			code := 500

			if strings.Contains(err.Error(), "not found in repo") {
				code = 404
			}

			http.Error(w, fmt.Sprintf("%v", err), code)
			return
		}

		committed := fileInfo.Committed
		timestamp := time.Unix(committed.GetSeconds(), int64(committed.GetNanos()))
		reader, err := pc.GetFileReadSeeker(repo, "master", file)
		if err != nil {
			http.Error(w, fmt.Sprintf("%v", err), 500)
			return
		}

		http.ServeContent(w, r, "", timestamp, reader)
	})

	http.ListenAndServe(fmt.Sprintf(":%d", port), nil)
}
{'fraction_non_alphanumeric': 0.1717171717171717, 'fraction_numerical': 0.029863855950812472, 'mean_word_length': 3.658486707566462, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3192387', 'n_tokens_mistral': 987, 'n_tokens_neox': 838, 'n_words': 207}