Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
efectn committed Jan 13, 2024
2 parents 2143492 + fa30b4e commit 1588b6b
Show file tree
Hide file tree
Showing 27 changed files with 527 additions and 283 deletions.
74 changes: 74 additions & 0 deletions .github/ISSUE_TEMPLATE/feature-request-v3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: "📝 Feature Proposal for v3"
title: "📝 [v3 Proposal]: "
description: Propose a feature or improvement for Fiber v3.
labels: ["📝 Proposal", "v3"]

body:
- type: markdown
id: notice
attributes:
value: |
### Notice
- For questions, join our [Discord server](https://gofiber.io/discord).
- Please write in clear, understandable English.
- Ensure your proposal aligns with Express design principles and HTTP RFC standards.
- Describe features expected to remain stable and not require changes in the foreseeable future.
- type: textarea
id: description
attributes:
label: "Feature Proposal Description"
description: "A clear and detailed description of the feature you are proposing for Fiber v3. How should it work, and what API endpoints and methods would it involve?"
placeholder: "Describe your feature proposal clearly and in detail, including API endpoints and methods."
validations:
required: true

- type: textarea
id: express-alignment
attributes:
label: "Alignment with Express API"
description: "Explain how your proposal aligns with the design and API of Express.js. Provide comparative examples if possible."
placeholder: "Outline how the feature aligns with Express.js design principles and API standards."
validations:
required: true

- type: textarea
id: standards-compliance
attributes:
label: "HTTP RFC Standards Compliance"
description: "Confirm that the feature complies with HTTP RFC standards, and describe any relevant aspects."
placeholder: "Detail how the feature adheres to HTTP RFC standards."
validations:
required: true

- type: textarea
id: stability
attributes:
label: "API Stability"
description: "Discuss the expected stability of the feature and its API. How do you ensure that it will not require changes or deprecations in the near future?"
placeholder: "Describe measures taken to ensure the feature's API stability over time."
validations:
required: true

- type: textarea
id: examples
attributes:
label: "Feature Examples"
description: "Provide concrete examples and code snippets to illustrate how the proposed feature should function."
placeholder: "Share code snippets that exemplify the proposed feature and its usage."
render: go
validations:
required: true

- type: checkboxes
id: terms
attributes:
label: "Checklist:"
description: "By submitting this issue, you confirm that:"
options:
- label: "I agree to follow Fiber's [Code of Conduct](https://github.com/gofiber/fiber/blob/master/.github/CODE_OF_CONDUCT.md)."
required: true
- label: "I have searched for existing issues that describe my proposal before opening this one."
required: true
- label: "I understand that a proposal that does not meet these guidelines may be closed without explanation."
required: true
54 changes: 54 additions & 0 deletions .github/ISSUE_TEMPLATE/maintenance-task-v3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: "🧹 v3 Maintenance Task"
title: "🧹 [v3 Maintenance]: "
description: Describe a maintenance task for the v3 of the Fiber project.
labels: ["🧹 Updates", "v3"]

body:
- type: markdown
id: notice
attributes:
value: |
### Notice
- Before submitting a maintenance task, please check if a similar task has already been filed.
- Clearly outline the purpose of the maintenance task and its impact on the project.
- Use clear and understandable English.
- type: textarea
id: task-description
attributes:
label: "Maintenance Task Description"
description: "Provide a detailed description of the maintenance task. Include any specific areas of the codebase that require attention, and the desired outcomes of this task."
placeholder: "Detail the maintenance task, specifying what needs to be done and why it is necessary."
validations:
required: true

- type: textarea
id: impact
attributes:
label: "Impact on the Project"
description: "Explain the impact this maintenance will have on the project. Include benefits and potential risks if applicable."
placeholder: "Describe how completing this task will benefit the project, or the risks of not addressing it."
validations:
required: false

- type: textarea
id: additional-context
attributes:
label: "Additional Context (optional)"
description: "Any additional information or context regarding the maintenance task that might be helpful."
placeholder: "Provide any additional information that may be relevant to the task at hand."
validations:
required: false

- type: checkboxes
id: terms
attributes:
label: "Checklist:"
description: "Please confirm the following:"
options:
- label: "I have confirmed that this maintenance task is currently not being addressed."
required: true
- label: "I understand that this task will be evaluated by the maintainers and prioritized accordingly."
required: true
- label: "I am available to provide further information if needed."
required: true
45 changes: 45 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE/v3-changes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## Description

Please provide a clear and concise description of the changes you've made and the problem they address. Include the purpose of the change, any relevant issues it solves, and the benefits it brings to the project. If this change introduces new features or adjustments, highlight them here.

Related to # (issue)

## Changes Introduced

List the new features or adjustments introduced in this pull request. Provide details on benchmarks, documentation updates, changelog entries, and if applicable, the migration guide.

- [ ] Benchmarks: Describe any performance benchmarks and improvements related to the changes.
- [ ] Documentation Update: Detail the updates made to the documentation and links to the changed files.
- [ ] Changelog/What's New: Include a summary of the additions for the upcoming release notes.
- [ ] Migration Guide: If necessary, provide a guide or steps for users to migrate their existing code to accommodate these changes.
- [ ] API Alignment with Express: Explain how the changes align with the Express API.
- [ ] API Longevity: Discuss the steps taken to ensure that the new or updated APIs are consistent and not prone to breaking changes.
- [ ] Examples: Provide examples demonstrating the new features or changes in action.

## Type of Change

Please delete options that are not relevant.

- [ ] New feature (non-breaking change which adds functionality)
- [ ] Enhancement (improvement to existing features and functionality)
- [ ] Documentation update (changes to documentation)
- [ ] Performance improvement (non-breaking change which improves efficiency)
- [ ] Code consistency (non-breaking change which improves code reliability and robustness)

## Checklist

Before you submit your pull request, please make sure you meet these requirements:

- [ ] Followed the inspiration of the Express.js framework for new functionalities, making them similar in usage.
- [ ] Conducted a self-review of the code and provided comments for complex or critical parts.
- [ ] Updated the documentation in the `/docs/` directory for [Fiber's documentation](https://docs.gofiber.io/).
- [ ] Added or updated unit tests to validate the effectiveness of the changes or new features.
- [ ] Ensured that new and existing unit tests pass locally with the changes.
- [ ] Verified that any new dependencies are essential and have been agreed upon by the maintainers/community.
- [ ] Aimed for optimal performance with minimal allocations in the new code.
- [ ] Provided benchmarks for the new code to analyze and improve upon.

## Commit Formatting

Please use emojis in commit messages for an easy way to identify the purpose or intention of a commit. You can refer to the emoji cheatsheet here: https://gitmoji.carloscuesta.me/

1 change: 1 addition & 0 deletions .github/scripts/sync_docs.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env bash
set -e

# Some env variables
BRANCH="main"
Expand Down
8 changes: 6 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,12 +459,16 @@ func (a *Agent) BodyStream(bodyStream io.Reader, bodySize int) *Agent {
}

// JSON sends a JSON request.
func (a *Agent) JSON(v any) *Agent {
func (a *Agent) JSON(v any, ctype ...string) *Agent {
if a.jsonEncoder == nil {
a.jsonEncoder = json.Marshal
}

a.req.Header.SetContentType(MIMEApplicationJSON)
if len(ctype) > 0 {
a.req.Header.SetContentType(ctype[0])
} else {
a.req.Header.SetContentType(MIMEApplicationJSON)
}

if body, err := a.jsonEncoder(v); err != nil {
a.errs = append(a.errs, err)
Expand Down
14 changes: 14 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,7 @@ func Test_Client_Agent_RetryIf(t *testing.T) {

func Test_Client_Agent_Json(t *testing.T) {
t.Parallel()
// Test without ctype parameter
handler := func(c Ctx) error {
require.Equal(t, MIMEApplicationJSON, string(c.Request().Header.ContentType()))

Expand All @@ -708,6 +709,19 @@ func Test_Client_Agent_Json(t *testing.T) {
}

testAgent(t, handler, wrapAgent, `{"success":true}`)

// Test with ctype parameter
handler = func(c Ctx) error {
require.Equal(t, "application/problem+json", string(c.Request().Header.ContentType()))

return c.Send(c.Request().Body())
}

wrapAgent = func(a *Agent) {
a.JSON(data{Success: true}, "application/problem+json")
}

testAgent(t, handler, wrapAgent, `{"success":true}`)
}

func Test_Client_Agent_Json_Error(t *testing.T) {
Expand Down
70 changes: 49 additions & 21 deletions ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,13 @@ func (t *TLSHandler) GetClientInfo(info *tls.ClientHelloInfo) (*tls.Certificate,
// Range data for c.Range
type Range struct {
Type string
Ranges []struct {
Start int
End int
}
Ranges []RangeSet
}

// RangeSet represents a single content range from a request.
type RangeSet struct {
Start int
End int
}

// Cookie data for c.Cookie
Expand Down Expand Up @@ -732,14 +735,20 @@ func (c *DefaultCtx) Is(extension string) bool {
// Array and slice values encode as JSON arrays,
// except that []byte encodes as a base64-encoded string,
// and a nil slice encodes as the null JSON value.
// This method also sets the content header to application/json.
func (c *DefaultCtx) JSON(data any) error {
// If the ctype parameter is given, this method will set the
// Content-Type header equal to ctype. If ctype is not given,
// The Content-Type header will be set to application/json.
func (c *DefaultCtx) JSON(data any, ctype ...string) error {
raw, err := c.app.config.JSONEncoder(data)
if err != nil {
return err
}
c.fasthttp.Response.SetBodyRaw(raw)
c.fasthttp.Response.Header.SetContentType(MIMEApplicationJSON)
if len(ctype) > 0 {
c.fasthttp.Response.Header.SetContentType(ctype[0])
} else {
c.fasthttp.Response.Header.SetContentType(MIMEApplicationJSON)
}
return nil
}

Expand Down Expand Up @@ -1093,25 +1102,44 @@ func (c *DefaultCtx) QueryFloat(key string, defaultValue ...float64) float64 {

// Range returns a struct containing the type and a slice of ranges.
func (c *DefaultCtx) Range(size int) (Range, error) {
var rangeData Range
var (
rangeData Range
ranges string
)
rangeStr := c.Get(HeaderRange)
if rangeStr == "" || !strings.Contains(rangeStr, "=") {
return rangeData, ErrRangeMalformed
}
data := strings.Split(rangeStr, "=")
const expectedDataParts = 2
if len(data) != expectedDataParts {

i := strings.IndexByte(rangeStr, '=')
if i == -1 || strings.Contains(rangeStr[i+1:], "=") {
return rangeData, ErrRangeMalformed
}
rangeData.Type = data[0]
arr := strings.Split(data[1], ",")
for i := 0; i < len(arr); i++ {
item := strings.Split(arr[i], "-")
if len(item) == 1 {
rangeData.Type = rangeStr[:i]
ranges = rangeStr[i+1:]

var (
singleRange string
moreRanges = ranges
)
for moreRanges != "" {
singleRange = moreRanges
if i := strings.IndexByte(moreRanges, ','); i >= 0 {
singleRange = moreRanges[:i]
moreRanges = moreRanges[i+1:]
} else {
moreRanges = ""
}

var (
startStr, endStr string
i int
)
if i = strings.IndexByte(singleRange, '-'); i == -1 {
return rangeData, ErrRangeMalformed
}
start, startErr := strconv.Atoi(item[0])
end, endErr := strconv.Atoi(item[1])
startStr = singleRange[:i]
endStr = singleRange[i+1:]

start, startErr := fasthttp.ParseUint(utils.UnsafeBytes(startStr))
end, endErr := fasthttp.ParseUint(utils.UnsafeBytes(endStr))
if startErr != nil { // -nnn
start = size - end
end = size - 1
Expand Down
6 changes: 4 additions & 2 deletions ctx_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,10 @@ type Ctx interface {
// Array and slice values encode as JSON arrays,
// except that []byte encodes as a base64-encoded string,
// and a nil slice encodes as the null JSON value.
// This method also sets the content header to application/json.
JSON(data any) error
// If the ctype parameter is given, this method will set the
// Content-Type header equal to ctype. If ctype is not given,
// The Content-Type header will be set to application/json.
JSON(data any, ctype ...string) error

// JSONP sends a JSON response with JSONP support.
// This method is identical to JSON, except that it opts-in to JSONP callback support.
Expand Down
Loading

0 comments on commit 1588b6b

Please sign in to comment.