Test_Ctx_Range_SuffixNormalization() — fiber Function Reference
Architecture documentation for the Test_Ctx_Range_SuffixNormalization() function in ctx_test.go from the fiber codebase.
Entity Profile
Dependency Diagram
graph TD c625a97b_fe81_16d0_a61a_b526f4e82261["Test_Ctx_Range_SuffixNormalization()"] 7b3d4933_5ae3_f84d_ff6d_0cb34e268026["ctx_test.go"] c625a97b_fe81_16d0_a61a_b526f4e82261 -->|defined in| 7b3d4933_5ae3_f84d_ff6d_0cb34e268026 style c625a97b_fe81_16d0_a61a_b526f4e82261 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
ctx_test.go lines 4248–4351
func Test_Ctx_Range_SuffixNormalization(t *testing.T) {
t.Parallel()
body := bytes.Repeat([]byte("x"), 123)
newApp := func() *App {
app := New()
app.Get("/", func(c Ctx) error {
rangesHeader := c.Get(HeaderRange)
if rangesHeader == "" {
return c.Send(body)
}
rangeData, err := c.Range(int64(len(body)))
if err != nil {
return err
}
if len(rangeData.Ranges) != 1 {
c.Status(StatusRequestedRangeNotSatisfiable)
c.Set(HeaderContentRange, fmt.Sprintf("bytes */%d", len(body)))
return ErrRequestedRangeNotSatisfiable
}
currentRange := rangeData.Ranges[0]
contentRange := fmt.Sprintf("bytes %d-%d/%d", currentRange.Start, currentRange.End, len(body))
c.Set(HeaderContentRange, contentRange)
statusCode := StatusPartialContent
if currentRange.Start == 0 && currentRange.End == int64(len(body))-1 {
statusCode = StatusOK
}
c.Status(statusCode)
return c.Send(body[currentRange.Start : currentRange.End+1])
})
return app
}
testCases := []struct {
name string
rangeHeader string
contentRange string
statusCode int
expectedBodySize int
}{
{
name: "suffix less than size",
rangeHeader: "bytes=-20",
contentRange: "bytes 103-122/123",
statusCode: StatusPartialContent,
expectedBodySize: 20,
},
{
name: "suffix equal to size",
rangeHeader: "bytes=-123",
contentRange: "bytes 0-122/123",
statusCode: StatusOK,
expectedBodySize: 123,
},
{
name: "suffix larger than size",
rangeHeader: "bytes=-9999",
contentRange: "bytes 0-122/123",
statusCode: StatusOK,
expectedBodySize: 123,
},
{
name: "unsatisfiable mixed ranges",
rangeHeader: "bytes=200-400,700-1200",
contentRange: "bytes */123",
statusCode: StatusRequestedRangeNotSatisfiable,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does Test_Ctx_Range_SuffixNormalization() do?
Test_Ctx_Range_SuffixNormalization() is a function in the fiber codebase, defined in ctx_test.go.
Where is Test_Ctx_Range_SuffixNormalization() defined?
Test_Ctx_Range_SuffixNormalization() is defined in ctx_test.go at line 4248.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free