Skip to content

🧹 [Maintenance]: Add a straightforward approach for accessing response headers in *fiber.Agent #3184

@xehrad

Description

@xehrad

Maintenance Task Description

Hello, Fiber team!

I’d like to propose a feature enhancement for Fiber’s *fiber.Agent. Currently, retrieving response headers requires extra steps that feel more complex than necessary, especially when compared to Go’s standard net/http package.

Current Situation

To access response headers, we need to manually set up the request and then access headers from the Response() object by iterating over them, which can be cumbersome. For example:

agent := app.AcquireAgent()
req := agent.Request()
req.Header.SetMethod(fiber.MethodGet)
req.SetRequestURI("https://example.com")

if err := agent.Do(req); err != nil {
	log.Fatal(err)
}

resp := req.Response()
resp.Header.VisitAll(func(key, value []byte) {
	fmt.Printf("%s: %s\n", string(key), string(value))
})

Proposed Solution

Could we add a more direct and intuitive method to access response headers directly from *fiber.Agent? For example:

agent := fiber.Get("<URL>")
resp, body, errs := agent.Bytes()
for key, value := range resp.GetRespHeaders() {
	fmt.Printf("%s: %s\n", key, value)
}

fmt.Printf("status: %s\n", resp.statusCode())

Benefits

  • Improved Developer Experience: Simplifies code for basic use cases, making it easier for developers to retrieve headers without extra setup.
  • Consistency with Go’s Standard Library: Aligns more closely with net/http, making the transition easier for those new to Fiber.

Thank you for considering this feature! It would make working with *fiber.Agent more intuitive and developer-friendly.

Impact on the Project

No response

Additional Context (optional)

No response

Checklist:

  • I have confirmed that this maintenance task is currently not being addressed.
  • I understand that this task will be evaluated by the maintainers and prioritized accordingly.
  • I am available to provide further information if needed.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions