Comments (7)
I don't think it happens very often that someone using a http handler will still also want to run fasthttp code. That's why you're the first one to have this issue. I'm afraid I don't have time to fix this now, but a pull request is always welcome.
from fasthttp.
The handler sets the status code which is captured by netHTTPResponseWriter
and then line 65 propagates that to the Response.
Can you show an example of something going wrong?
from fasthttp.
The handler sets the status code which is captured by
netHTTPResponseWriter
and then line 65 propagates that to the Response.Can you show an example of something going wrong?
netHTTPResponseWriter is missing the initialization of statusCode, so when it propagates it propagates a nil value.
its not setting the context status that comes from the caller.
from fasthttp.
But that's no problem, cause in net/http
not setting a status code means 200
and that's exactly what it is doing here:
fasthttp/fasthttpadaptor/adaptor.go
Lines 98 to 100 in d3aa5a1
Or do you mean that you are setting a status code before you call the handler returned by NewFastHTTPHandler
and want it to use that?
Like I said, show me an example of this going wrong.
from fasthttp.
But that's no problem, cause in
net/http
not setting a status code means200
and that's exactly what it is doing here:fasthttp/fasthttpadaptor/adaptor.go
Lines 98 to 100 in d3aa5a1
Or do you mean that you are setting a status code before you call the handler returned by
NewFastHTTPHandler
and want it to use that?Like I said, show me an example of this going wrong.
Yes I mean to set the status code before calling the HTTPHandler. It needs to be set on line 59.
// For example imagine a Login handler that wants to set a status
// HTMX handles status to render differently, for example.
func LoginHandler(c *fiber.Ctx) error {
// ........
if isBadRequest {
c.Status(http.StatusBadRequest) <---- this will be converted to 200 always.
return Render(c, dialog.BadRequest())
}
return Render(c, pages.Login())
}
func Render(c *fiber.Ctx, component templ.Component, options ...func(*templ.ComponentHandler)) error {
componentHandler := templ.Handler(component)
for _, o := range options {
o(componentHandler)
}
return adaptor.HTTPHandler(componentHandler)(c)
}```
from fasthttp.
Interesting use case. But in that case can't you just turn it around and do this?
if isBadRequest {
Render(c, dialog.BadRequest())
c.Status(http.StatusBadRequest)
}
from fasthttp.
You might not know where the Status was set, if the HTTPHandler will reset it you need to get a copy beforehand to set it again afterwards. I found this issue while debugging Templ code using go.fiber, I don't control the adaptor, I just use it on my project.
https://github.com/a-h/templ/blob/main/examples/integration-gofiber/main.go
I think it should just respect the Status, the code above I just wrote it as an example.
from fasthttp.
Related Issues (20)
- how can i use fasthttp bare minimum "net" library only without routing through the http overhead? just pure tcp rpc stuff will do HOT 1
- What is a correct way to create a proper fasthttp.RequestCtx in the unit tests? HOT 1
- Timeout stream response connection does not clear buffer data for re-use HOT 2
- Propagate request error to RetryIfFunc HOT 1
- Expose `timeout` field in Request HOT 1
- NewFastHTTPHandler does not set response status code. HOT 1
- Error when serving connection "x.x.x.x:443"<->"172.56.198.126:18271": EOF HOT 3
- http parsing of the request line - where does that happen? HOT 1
- gnet is going to have tls working on it very soon. was wondering if anyone has tried to port fasthttp to use gnet instead. HOT 1
- Feature request : update and show all examples for doing zero allocation when using fasthttp. 100% zero alloc for each req / resp. HOT 3
- It is not safe to read all stream body to memory without a max size limit. HOT 1
- serving a compress enabled public folder without +w permissions results in a 404 HOT 1
- no free connections available to host HOT 3
- when setting MaxConnsPerIP to value greater than zero, the TLSConnectionState( ) is null on a TLS connection returned from the worker pool. HOT 11
- invalid memory address or nil pointer dereference for firstByteReader'c HOT 2
- peeking nested query args HOT 1
- Incorrect Tag for version 1.54.0 HOT 1
- PFlag/Cobra compatibility in prefork HOT 1
- `\r` is improperly permitted in header names. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fasthttp.