-
Notifications
You must be signed in to change notification settings - Fork 284
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
Code deduplication + IPv6 HTTP client fix #2346
Conversation
b5f4580
to
23deade
Compare
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.
Made a few comments.
http/vibe/http/client.d
Outdated
enforce(url.schema == "http" || url.schema == "https", "URL schema must be http(s)."); | ||
} | ||
enforce(url.host.length > 0, "URL must contain a host name."); | ||
bool use_tls; |
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.
Instead of creating a variable, you can just return
when it is set, because the variable is only ever assigned to once
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.
I want to avoid changes as much as possible so as not to add any error here. It's okay if such a variable stays here for a while. And personally I do not like many exit points.
http/vibe/http/client.d
Outdated
@@ -173,6 +134,38 @@ private bool isTlsNeed(in URL url, in HTTPClientSettings settings) | |||
return use_tls; | |||
} | |||
|
|||
//TODO: remove @trusted | |||
private void httpRequesterDg(scope HTTPClientRequest req, in URL url, in HTTPClientSettings settings, scope void delegate(scope HTTPClientRequest req) requester) @trusted |
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.
If the delegate
aren't @safe
, this can't be marked @trusted
, ever
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.
This is already tagged as "Outdated".
I used @trusted here temporary to not to make a mistake by making a big change right away
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.
In that case you could add @system
to httpRequesterDg
instead. @trusted
is bad, because it communicates that the contained code has been manually verified to be safe, which is of course not the case with a user supplied callback.
Of course the next step at some point will be to templatize the callback parameter and let the compiler infer the safety of the function (which currently requires putting it in a different scope or replacing the @safe:
at the beginning of the file).
EDIT: I just saw what you mean with the wohle block being trusted before, so I'm fine with the current intermediate step!
|
||
License: Subject to the terms of the MIT license, as written in the included LICENSE.txt file. | ||
*/ | ||
module vibe.http.auth.basic_auth_client; |
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.
Why the new module ? If it's only for one function I am not sure it's worth it.
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.
It is need to avoid cyclic dependency of ctors/dtors between HTTP client and server modules what both use basic_auth
module otherwise
http/vibe/http/client.d
Outdated
|
||
if (requester) requester(req); | ||
if (requester) () @trusted{ requester(req); } (); |
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.
There's no point in using @safe
if we trust a random external delegate.
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.
In fact, if look carefully, initially all of this code block was unsafe - otherwise, how would such call marked here by red color work at all? Now only one line of it marked as trusted.
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.
In other words, we previously trusted to it too and nothing changed.
029a0ae
to
0ff7610
Compare
One test failed on CI side again |
http/vibe/http/client.d
Outdated
assert(!cli.m_responding, "HTTP client still responding after return!?"); | ||
} | ||
|
||
private bool isTlsNeed(in URL url, in HTTPClientSettings settings) |
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.
Naming: isTLSNeeded
or isTLSRequired
http/vibe/http/client.d
Outdated
@@ -173,6 +134,38 @@ private bool isTlsNeed(in URL url, in HTTPClientSettings settings) | |||
return use_tls; | |||
} | |||
|
|||
//TODO: remove @trusted | |||
private void httpRequesterDg(scope HTTPClientRequest req, in URL url, in HTTPClientSettings settings, scope void delegate(scope HTTPClientRequest req) requester) @trusted |
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.
In that case you could add @system
to httpRequesterDg
instead. @trusted
is bad, because it communicates that the contained code has been manually verified to be safe, which is of course not the case with a user supplied callback.
Of course the next step at some point will be to templatize the callback parameter and let the compiler infer the safety of the function (which currently requires putting it in a different scope or replacing the @safe:
at the beginning of the file).
EDIT: I just saw what you mean with the wohle block being trusted before, so I'm fine with the current intermediate step!
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.
About the auth_basic
changes, the fact that it creates a new public mini-module is really unfortunate. A more suitable solution may be to create a new vibe.http.internal.*
module that contains the implementation, which is in turn used by vibe.http.client
and exposed though vibe.http.auth.auth_basic
. That just also requires taking care of the ddox-filter arguments in the main dub.sdl file.
I'm not sure about the name of that internal module, since it will only contain one almost trivial function, but since it's internal, it doesn't really matter that much and auth_basic
is just fine for now. The function itself could even be marked as package(vibe.http)
in addition to not being documented.
Maybe some another functions will be moved to it too? I just moved this one because compilation issue. (But this change can be left for the future.) |
Agreed, but we can freely change the module name later as required, so it really just shouldn't become a reason to worry about now. |
(I did not notice the asterisk.) It turns out to not very look good (as for me) with the same result: I think it's better to leave it as it is now. |
I'm mostly concerned with the public API. The internal module is a little silly for the amount of code it contains, but that's fine if the alternative is to have a public module with the same issue, plus making a pointless breaking change. |
What if I am just remove |
Yes, it's still a normal public module in that case. The convention is that any |
Removes multiple copy-and-pasted lines from HTTP client module.
Fixes ommited support of IPv6 addresses in two of four requestHTTP fuctions
Adds module vibe.http.auth.basic_auth_client to avoid cyclic dependency of ctors/dtors between HTTP client and server code.
@safe coverage slightly increased