aboutsummaryrefslogtreecommitdiff
path: root/lib/http/range_position_example_test.go
blob: 8d8177c325dc67e41e17133ec302430e2daef07a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package http_test

import (
	"fmt"

	libhttp "git.sr.ht/~shulhan/pakakeh.go/lib/http"
)

func ExampleParseContentRange() {
	fmt.Println(libhttp.ParseContentRange(`bytes 10-/20`))   // Invalid, missing end.
	fmt.Println(libhttp.ParseContentRange(`bytes 10-19/20`)) // OK
	fmt.Println(libhttp.ParseContentRange(`bytes -10/20`))   // Invalid, missing start.
	fmt.Println(libhttp.ParseContentRange(`10-20/20`))       // Invalid, missing unit.
	fmt.Println(libhttp.ParseContentRange(`bytes 10-`))      // Invalid, missing "/size".
	fmt.Println(libhttp.ParseContentRange(`bytes -10/x`))    // Invalid, invalid "size".
	fmt.Println(libhttp.ParseContentRange(`bytes`))          // Invalid, missing position.
	// Output:
	// <nil> ParseContentRange: invalid Content-Range "bytes 10-/20": strconv.ParseInt: parsing "": invalid syntax
	// 10-19 <nil>
	// <nil> ParseContentRange: invalid Content-Range "bytes -10/20"
	// <nil> ParseContentRange: invalid Content-Range "10-20/20"
	// <nil> ParseContentRange: invalid Content-Range "bytes 10-"
	// <nil> ParseContentRange: invalid Content-Range "bytes -10/x"
	// <nil> ParseContentRange: invalid Content-Range "bytes"
}