githttp

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2026 License: BSD-3-Clause Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package githttp serves git clone and fetch over smart HTTP, protocol version 2 only, anonymously and for public repositories only (gitprotocol-http, gitprotocol-v2).

Two requests exist: GET <repo>/info/refs?service=git-upload-pack, which answers the capability advertisement, and POST <repo>/git-upload-pack, which answers one command request (stateless-rpc). Push, the dumb protocol and protocol versions 0 and 1 are refused with a message that says so.

A repository that does not exist and one the caller may not read both answer 404, so a name cannot be probed. gitprotocol-http asks for 403 when the repository exists and is not permitted; that is a deliberate departure.

Index

Constants

View Source
const (
	// MaxPathLen is the longest request path read at all.
	MaxPathLen = 512
	// DefaultMaxBody bounds a request body as it travels (compressed or not).
	DefaultMaxBody = 8 << 20
)

Bounds that are not configurable.

Variables

View Source
var ErrRoute = errors.New("no such resource")

ErrRoute is returned for a path that is none of the endpoints.

Functions

This section is empty.

Types

type Endpoint

type Endpoint int

Endpoint is the part of a request path after the repository.

const (
	InfoRefs Endpoint = iota + 1
	UploadPack
	ReceivePack
)

The endpoints a request path may end in.

func ParsePath

func ParsePath(p string) (gitrepo.Name, Endpoint, error)

ParsePath splits a request path into the repository and the endpoint. It is strict: a path longer than MaxPathLen, with a byte outside printable ASCII, or whose repository part is not owner/name[.git] is refused.

type Handler

type Handler struct {
	Repos    *gitrepo.Service
	Sessions *gitrepo.Limiter // keyed by client address
	Log      *slog.Logger

	// RequestTimeout bounds one request (0: gitrepo's default).
	RequestTimeout time.Duration
	// MaxBody bounds a request body as sent (0: DefaultMaxBody).
	MaxBody int64
}

Handler is the smart HTTP git server.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL