-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
httpclient Response object references original Request; refs #16685 #16691
Conversation
* Avoid ambiguous identifier collision with asynchttpserver Request object
@dom96 thanks for the feedback, updated |
doAssert req.reqMethod == HttpGet | ||
doAssert $req.url == "http://example.com/" | ||
let clientAgent = $req.headers["user-agent"] | ||
doAssert clientAgent.contains("Nim httpclient") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DRY:
doAssert clientAgent.contains("Nim httpclient") | |
doAssert clientAgent == defUserAgent |
template testPreparedRequest(req: PreparedRequest) = | ||
doAssert req.reqMethod == HttpGet | ||
doAssert $req.url == "http://example.com/" | ||
let clientAgent = $req.headers["user-agent"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let clientAgent = $req.headers["user-agent"] | |
let clientAgent = req.headers["user-agent"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM after addressing remaining comments
let's wait until #16710 |
Co-authored-by: Dominik Picheta <[email protected]>
What are the use cases? In general you should avoid keeping everything in memory just because somebody might need it later. The "later" may never come but everybody pays the price. (Higher memory consumption.) |
@Araq I'd have to think more on the broader range of use cases for the community, but here are some immediate examples:
Without the original request attached to the Response, the original Uri, HttpHeader, other related request data needs to be passed along with the Response and may lead to more verbose, error-prone code. Just as a quick hacky example:
|
For debugging, make the debugging code opt-in. |
This should be compile-time opt-in, |
it's not just for debugging, but how about this: type RequestOption* = object
preparedRequest*: bool
# can grow in future
proc initRequestOption(): RequestOption = RequestOption(preparedRequest: false)
proc request(..., option = initRequestOption()) = ... rationale for object instead of |
For the best of both worlds, just put these additions behind a define: |
I don't see how Also, |
On a related note what's the possibility of the Nim/lib/pure/asynchttpserver.nim Lines 59 to 66 in a90f7a6
|
I like the idea of a shared Request object, if it is possible. If you really taking the effort to improve it, would be better first to fix httpclient to be reusable, as it is now is kinda single-shot thing, |
|
This is not opt-in. Please re-open once addressed. |
how about add a property like |
request
field toResponse
&AsyncResponse
objects,thttpclient.nim
tasynchttpserver.nim