Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
3 tasks done
xehrad opened this issue Oct 29, 2024 · 5 comments
Open
3 tasks done

Comments

@xehrad
Copy link

xehrad commented Oct 29, 2024

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.
Copy link

welcome bot commented Oct 29, 2024

Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

@gaby gaby added v2 and removed v3 labels Oct 31, 2024
@gaby
Copy link
Member

gaby commented Oct 31, 2024

@efectn Maybe for v3 we should make the functions have the same naming convention as net/http?

@TusharMohapatra07
Copy link

Hey, so you want to implement this from scratch or just implement new functions that does the same thing that you've mentioned (in current situation section) under the hood.

@gaby
Copy link
Member

gaby commented Nov 5, 2024

@TusharMohapatra07 We already have this functionality in v3. We are not adding any new features to v2 at the moment, only bug fixes.

On the other hand, it might be worth revisiting the names of the functions for the v3 client.

@efectn
Copy link
Member

efectn commented Nov 5, 2024

@efectn Maybe for v3 we should make the functions have the same naming convention as net/http?

Yes we can do it for better naming convention

@ReneWerner87 ReneWerner87 added v3 and removed v2 labels Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants