main bac21c6

http_timeouts.go RawHistoryFolder

1package domain
2
3import (
4	"fmt"
5	"time"
6)
7
8// Default HTTP server timeouts.
9const (
10	DefaultRegistryReadHeaderTimeout = 10 * time.Second
11	DefaultRegistryReadTimeout       = 5 * time.Minute
12	DefaultRegistryWriteTimeout      = 5 * time.Minute
13	DefaultRegistryIdleTimeout       = 120 * time.Second
14
15	DefaultEntryPointReadHeaderTimeout   = 5 * time.Second
16	DefaultEntryPointIdleTimeout         = 30 * time.Second
17	DefaultEntryPointTransferIdleTimeout = 2 * time.Minute
18)
19
20// RegistryHTTPTimeouts holds the fixed timeouts of the registry HTTP servers
21// (config section server.http). Read and Write timeouts bound the whole
22// request and response, which suits registry API calls.
23type RegistryHTTPTimeouts struct {
24	ReadHeaderTimeout time.Duration
25	ReadTimeout       time.Duration
26	WriteTimeout      time.Duration
27	IdleTimeout       time.Duration
28}
29
30// DefaultRegistryHTTPTimeouts returns the default registry server timeouts.
31func DefaultRegistryHTTPTimeouts() RegistryHTTPTimeouts {
32	return RegistryHTTPTimeouts{
33		ReadHeaderTimeout: DefaultRegistryReadHeaderTimeout,
34		ReadTimeout:       DefaultRegistryReadTimeout,
35		WriteTimeout:      DefaultRegistryWriteTimeout,
36		IdleTimeout:       DefaultRegistryIdleTimeout,
37	}
38}
39
40// WithDefaults replaces zero values with the defaults.
41func (t RegistryHTTPTimeouts) WithDefaults() RegistryHTTPTimeouts {
42	defaults := DefaultRegistryHTTPTimeouts()
43	if t.ReadHeaderTimeout == 0 {
44		t.ReadHeaderTimeout = defaults.ReadHeaderTimeout
45	}
46	if t.ReadTimeout == 0 {
47		t.ReadTimeout = defaults.ReadTimeout
48	}
49	if t.WriteTimeout == 0 {
50		t.WriteTimeout = defaults.WriteTimeout
51	}
52	if t.IdleTimeout == 0 {
53		t.IdleTimeout = defaults.IdleTimeout
54	}
55	return t
56}
57
58// Validate rejects negative durations. Zero values mean "use the default".
59func (t RegistryHTTPTimeouts) Validate() error {
60	return validateNonNegativeDurations(map[string]time.Duration{
61		"server.http.read_header_timeout": t.ReadHeaderTimeout,
62		"server.http.read_timeout":        t.ReadTimeout,
63		"server.http.write_timeout":       t.WriteTimeout,
64		"server.http.idle_timeout":        t.IdleTimeout,
65	})
66}
67
68// HTTPOptions holds the timeouts of the HTTP servers behind traffic
69// entrypoints (config section traffic.http).
70//
71// There is deliberately no fixed read or write timeout: ReadHeaderTimeout
72// bounds the request header, IdleTimeout bounds keep-alive connections, and
73// TransferIdleTimeout cuts a transfer only after that long without data in
74// the direction being waited on.
75type HTTPOptions struct {
76	ReadHeaderTimeout   time.Duration
77	IdleTimeout         time.Duration
78	TransferIdleTimeout time.Duration
79}
80
81// DefaultHTTPOptions returns the default entrypoint HTTP timeouts.
82func DefaultHTTPOptions() HTTPOptions {
83	return HTTPOptions{
84		ReadHeaderTimeout:   DefaultEntryPointReadHeaderTimeout,
85		IdleTimeout:         DefaultEntryPointIdleTimeout,
86		TransferIdleTimeout: DefaultEntryPointTransferIdleTimeout,
87	}
88}
89
90// WithDefaults replaces zero values with the defaults.
91func (o HTTPOptions) WithDefaults() HTTPOptions {
92	defaults := DefaultHTTPOptions()
93	if o.ReadHeaderTimeout == 0 {
94		o.ReadHeaderTimeout = defaults.ReadHeaderTimeout
95	}
96	if o.IdleTimeout == 0 {
97		o.IdleTimeout = defaults.IdleTimeout
98	}
99	if o.TransferIdleTimeout == 0 {
100		o.TransferIdleTimeout = defaults.TransferIdleTimeout
101	}
102	return o
103}
104
105// Validate rejects negative durations. Zero values mean "use the default".
106func (o HTTPOptions) Validate() error {
107	return validateNonNegativeDurations(map[string]time.Duration{
108		"traffic.http.read_header_timeout":   o.ReadHeaderTimeout,
109		"traffic.http.idle_timeout":          o.IdleTimeout,
110		"traffic.http.transfer_idle_timeout": o.TransferIdleTimeout,
111	})
112}
113
114func validateNonNegativeDurations(values map[string]time.Duration) error {
115	for name, value := range values {
116		if value < 0 {
117			return fmt.Errorf("%s must be positive", name)
118		}
119	}
120	return nil
121}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close