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

how to return custom http response data and header #1130

Open
brucke opened this issue Oct 19, 2024 · 9 comments · May be fixed by #1165
Open

how to return custom http response data and header #1130

brucke opened this issue Oct 19, 2024 · 9 comments · May be fixed by #1165
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers Service Related to external http, grpc communciation , middlewares etc.

Comments

@brucke
Copy link

brucke commented Oct 19, 2024

Hey,

I tried gofr for one of my Projects. I'm realy happy with it, but now I faced a big blocking point to continue with gofr.

I want to return a custom http response.

Data: string
And a lot of http headers

But at the moment I can't find the API to do it. I analyzed the source code and found the Responder and also the response.Raw and response.File but that's not sufficient. I have to add more custom headers. So only way I see at the moment is CustomMiddleware but from my point of view this feels wrong.

Because it's not possible to attach a middleware to a dedicated route only globally.

Has anybody a hit / idea for me?

@vipul-rawat
Copy link
Member

Hey @brucke, can you please elaborate on the use case where and what response headers you want to send?

@vipul-rawat vipul-rawat added the question Further information is requested label Oct 28, 2024
@brucke
Copy link
Author

brucke commented Oct 28, 2024

Hey,
I generate calendar based on different settings which can be subscribe for instance by google calendar.

for instance:

	w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%v.ics", childId))
	w.Header().Set("Cache-Control", "no-cache, no-store, max-age=0, must-revalidate")
	w.Header().Set("Content-Type", "text/calendar")
	w.Write([]byte(cal.Serialize()))
	w.WriteHeader(200)

And I have a plain text like: https://de.wikipedia.org/wiki/ICalendar

@vipul-rawat
Copy link
Member

vipul-rawat commented Oct 29, 2024

Hey @brucke, I understand your use case. We already have the response.File("gofr.dev/pkg/gofr/http/response") struct for returning file data, where you can set the content type.
As for the Content-Disposition and Cache-Control, we can add support for sending custom headers with the response.

The ideal way would be to add a header field to the response and populate the headers to the responder after the handler is called.

@vipul-rawat vipul-rawat added enhancement New feature or request good first issue Good for newcomers Service Related to external http, grpc communciation , middlewares etc. and removed question Further information is requested labels Oct 29, 2024
@rigved-telang
Copy link

@vipul-rawat hey can you please assign this issue to me?

rigved-telang pushed a commit to rigved-telang/gofr that referenced this issue Oct 30, 2024
rigved-telang added a commit to rigved-telang/gofr that referenced this issue Oct 30, 2024
@brucke
Copy link
Author

brucke commented Oct 30, 2024

Thanks :) I try it today if it fits my needs.

rigved-telang added a commit to rigved-telang/gofr that referenced this issue Oct 30, 2024
@rigved-telang
Copy link

Hey @vipul-rawat, I needed a little help. I added a new response.go under the pkg/gofr/http/response directory, now I want to use my local files in another project to test if my functionality is working, how can i do that, I tried doing replace gofr.dev/pkg/gofr => ../gofr/pkg/gofr but that is not working.

@vipul-rawat
Copy link
Member

Hey @rigved-telang, replace it until the first gofr folder
gofr.dev => ../gofr
You can replace only the module and not just one package.

@rigved-telang
Copy link

thanks, it worked

@rigved-telang
Copy link

And in the gofr repo itself, the replace line should be replace gofr.dev => ./ right? Currently I had put the line as replace gofr.dev/pkg/gofr => ./pkg/gofr and that was working. I am sorry I am new to go hence the confusion.

rigved-telang added a commit to rigved-telang/gofr that referenced this issue Oct 30, 2024
rigved-telang added a commit to rigved-telang/gofr that referenced this issue Oct 30, 2024
@rigved-telang rigved-telang linked a pull request Oct 30, 2024 that will close this issue
4 tasks
rigved-telang added a commit to rigved-telang/gofr that referenced this issue Oct 31, 2024
rigved-telang added a commit to rigved-telang/gofr that referenced this issue Oct 31, 2024
rigved-telang added a commit to rigved-telang/gofr that referenced this issue Oct 31, 2024
rigved-telang added a commit to rigved-telang/gofr that referenced this issue Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers Service Related to external http, grpc communciation , middlewares etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants