Fasthttp: Question: Why everything seems functional?

Created on 9 Jul 2019  路  3Comments  路  Source: valyala/fasthttp

This is not an actual issue, This is a question. I hope the community will help me well.

The net/http package has everything like request.Host or request.Headers. On the other hand fasthttp has everything like request.Host()....

Are there any special reason for this? If yes, please help me to understand.

Thanks!

Most helpful comment

Hello,

As an open package, the library should provide an easy API at the same time keeps many functionalities in private. Making the user accessing functions instead of the object itself will allow the developers/maintainers of the package to change easily the functionality of the functions (getters and setters) without breaking backward compatibility.

All 3 comments

A lot of this design comes from @valyala who normally never responds to issues here, so it will be hard to know for sure.

But a lot of this design comes from doing the least amount of work possible. net/http has to populate all these fields for every request. fasthttp for example doesn't parse all the headers until you actually try to get the value of one of the headers. Because you need to call a function to get the value we can wait with parsing the headers until you actually call this function. Because the headers are a map in net/http (and there are no map getter functions) it always needs to parse them and fill this map. Even if you don't use them.

Hello,

As an open package, the library should provide an easy API at the same time keeps many functionalities in private. Making the user accessing functions instead of the object itself will allow the developers/maintainers of the package to change easily the functionality of the functions (getters and setters) without breaking backward compatibility.

@dgrr
for high performance, more detail control is good for some developer like me.
get some field only from http header or http payload, but not to automatic handle all every time.
it's a trade-off to make development "easy" or make high performance in running.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Fenny picture Fenny  路  4Comments

jeremyjpj0916 picture jeremyjpj0916  路  5Comments

gogoods picture gogoods  路  3Comments

bullardla picture bullardla  路  5Comments

unisqu picture unisqu  路  4Comments