Comments (9)
So this would mean the Request will keep around its payload for the complete request-response flow. I guess that should not put an extra strain on the processing or memory consumption; the request will do a ioutil.ReadAll(r.Request.Body) anyway. In addition, route functions (or filters) must call ReadEntity explicitly so those that need streaming access are not affected.
Alternatively, you could store the entity in a request attributes (using SetAttribute) and pick it up later in the function (Get)
Putting the implementation aside, I am curious why a filter would need the payload ahead of the route function. Can you give an example?
from go-restful.
Example: If you are using a filter to check for whether a particular action( i.e. a POST) and validate the request can be properly created before the particular action is executed.
I see your point about setAttribute, but if you are creating a set of "mix and match" filters and functions, it seems to me you would not necessarily know if read entity had been called already. having to check and then calling it yourself and using setAttribute would get a little tedious and annoying after a while.
from go-restful.
Agree, using your solution the route functions do not need to be aware of the fact that the entity may have been read earlier in the process.
I have merged your changes. Thanks.
from go-restful.
Recently, I got a merge request that invalidates this feature ( caching the resource for re-reading) for performance reasons (imagine what impact large content could have). Instead, I would like to propose to use the request attribute for this special case. ( see earlier discussion).
from go-restful.
That totally makes sense. It's a performance issue for some folks. There's now the issue of backwards compatibility, though.
Also, this would lead to a lot of boilerplate code like the following:
data := request.Attribute("cachedData")
if data == nil {
err := request.ReadEntity(data)
if err != nil {
return err
}
request.SetAttribute("cachedData", data)
}
// Now I can use data.
We could add a method that does this boilerplate:
func (req *Request) ReadCachedEntity(interface{}) (error)
This could be implemented internally using attributes, or by adding an interface{} field to the Request struct. Would need some documentation to explain that folks should either use this or ReadEntity, but not both.
Thing is, that's exactly what ReadEntity
does today. It's also what clients have come to expect.
Another option would be to provide a new method that does the performant thing by not caching for folks who don't want to use the caching scheme:
func (req *Request) ReadEntityWithoutCaching(interface{}) (error)
Then encourage folks who don't need caching to use that. I believe that may be the lightest burden on existing users.
Thoughts?
from go-restful.
Breaking the API is indeed not an option. Thank you for your suggestions to handle this. Give me some time to think about the solutions.
from go-restful.
How about this alternative. We introduce a setting that can be changed with SetCacheReadEntity() and make ReadEntity behave accordingly. Default value would be true so not change w.r.t current status
from go-restful.
Sounds great!
On Tue, Jun 17, 2014 at 11:22 PM, Ernest Micklei [email protected]
wrote:
How about this alternative. We introduce a setting that can be changed
with SetCacheReadEntity() and make ReadEntity behave accordingly. Default
value would be true so not change w.r.t current status—
Reply to this email directly or view it on GitHub
#74 (comment).
Jeff Carollo
Software Engineer
usermind
p 206.535.2867 x110
m 979.574.1534
from go-restful.
So what should we do now? is there any way to re-read request?
from go-restful.
Related Issues (20)
- [feature] add prometheus metric filter HOT 3
- Please deploy update of v2 to https://pkg.go.dev/ HOT 9
- How to reset the default container HOT 1
- Request.QueryParameter function consumes large memory for big request HOT 3
- Support for multiple return types HOT 5
- (discussion) PrettyPrintResponses default value to false HOT 2
- Tokenizer change in 3.10 breaks many URLs HOT 33
- Security - PRISMA-2022-0227 - High Sev - emicklei/go-restful/v3 module prior to v3.10.0 is vulnerable HOT 3
- using path.Join breaks the current api HOT 6
- The go-restful-swagger12 not support go-restful version 3 HOT 4
- Whether to support a unified request results interceptors HOT 1
- which PR broke the compatible against v3.10.0 HOT 1
- Flush don't work HOT 7
- Questions about WebService Path HOT 2
- Security is not exposed in RouteBuilder HOT 6
- Improper handling of empty POST requests. HOT 5
- Why were the patch versions for vulnerability (snyk id:SNYK-GOLANG-GITHUBCOMEMICKLEIGORESTFULV3-2435654) released so late? HOT 2
- default values of a slice field in a Go struct HOT 3
- Evaluation HOT 1
- List all request headers 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 go-restful.