Skip to content
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

Merged
merged 9 commits into from
Aug 21, 2019

Conversation

denizzzka
Copy link
Contributor

@denizzzka denizzzka commented Aug 10, 2019

  • 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

Copy link
Contributor

@Geod24 Geod24 left a 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.

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;
Copy link
Contributor

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

Copy link
Contributor Author

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.

@@ -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
Copy link
Contributor

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

Copy link
Contributor Author

@denizzzka denizzzka Aug 10, 2019

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

Copy link
Member

@s-ludwig s-ludwig Aug 14, 2019

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!

http/vibe/http/auth/basic_auth.d Show resolved Hide resolved

License: Subject to the terms of the MIT license, as written in the included LICENSE.txt file.
*/
module vibe.http.auth.basic_auth_client;
Copy link
Contributor

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.

Copy link
Contributor Author

@denizzzka denizzzka Aug 10, 2019

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


if (requester) requester(req);
if (requester) () @trusted{ requester(req); } ();
Copy link
Contributor

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.

Copy link
Contributor Author

@denizzzka denizzzka Aug 10, 2019

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.

Copy link
Contributor Author

@denizzzka denizzzka Aug 10, 2019

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.

@denizzzka
Copy link
Contributor Author

One test failed on CI side again

assert(!cli.m_responding, "HTTP client still responding after return!?");
}

private bool isTlsNeed(in URL url, in HTTPClientSettings settings)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming: isTLSNeeded or isTLSRequired

@@ -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
Copy link
Member

@s-ludwig s-ludwig Aug 14, 2019

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!

Copy link
Member

@s-ludwig s-ludwig left a 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.

@denizzzka
Copy link
Contributor Author

denizzzka commented Aug 14, 2019

I'm not sure about the name of that internal module, since it will only contain one almost trivial function

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.)

@s-ludwig
Copy link
Member

Maybe some another functions will be moved to it too? I just moved 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.

@denizzzka
Copy link
Contributor Author

denizzzka commented Aug 17, 2019

A more suitable solution may be to create a new vibe.http.internal.*

This solution may lead to same cyclic dependency in the future when some another functions will be moved to it. (Because internal.* sounds like that it should contain both client and server code)

(I did not notice the asterisk.)

It turns out to not very look good (as for me) with the same result:vibe.http.internal.basic_auth_client. Moreover, in fact, addBasicAuth aren't internal function - this is a function that is designed to call by users.

I think it's better to leave it as it is now.

@s-ludwig
Copy link
Member

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.

@denizzzka
Copy link
Contributor Author

What if I am just remove deprecated from alias addBasicAuth = vibe.http.auth.basic_auth_client.addBasicAuth;? Will documentation also be rendered for vibe.http.auth.basic_auth module? In this case no one will notice anything and nothing will need to be changed in the user code.

@s-ludwig
Copy link
Member

Yes, it's still a normal public module in that case. The convention is that any *.internal.* modules will be hidden from the documentation.

@s-ludwig s-ludwig merged commit 4bf3f58 into vibe-d:master Aug 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants