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

fix #2222 #2223

Merged
merged 8 commits into from
Nov 6, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions inet/vibe/inet/url.d
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,13 @@ struct URL {
const {
import std.format;
auto dst = appender!string();
dst.put(schema);
dst.put(":");
if (isDoubleSlashSchema(schema))
dst.put("//");
if (schema.length)
{
dst.put(schema);
dst.put(":");
if (isDoubleSlashSchema(schema))
dst.put("//");
}
Copy link
Member

Choose a reason for hiding this comment

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

Without the schema, the generated string is not a URL anymore. Of course it could be argued to extend this class into a full URI, but since this is just a side-effect, I'd like to keep that a separate question. Without having looked at the JS generation code too closely, to me it seems like this optimization should be handled there. If I'm not mistaken, this should also be made an opt-in/out setting, since the JS might be accessed from page hosted on a different server or sub domain.

if (m_username.length || m_password.length) {
dst.put(username);
dst.put(':');
Expand Down
16 changes: 9 additions & 7 deletions web/vibe/web/internal/rest/common.d
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,7 @@ import std.traits : hasUDA;
import vibe.internal.meta.uda : findFirstUDA;

this.settings = settings ? settings.dup : new RestInterfaceSettings;
if (is_client) {
assert(this.settings.baseURL != URL.init,
"RESTful clients need to have a valid RestInterfaceSettings.baseURL set.");
} else if (this.settings.baseURL == URL.init) {
if (this.settings.baseURL == URL.init && !is_client) {
// use a valid dummy base URL to be able to construct sub-URLs
// for nested interfaces
this.settings.baseURL = URL("http://localhost/");
Expand All @@ -135,9 +132,14 @@ import std.traits : hasUDA;
this.basePath = concatURL(this.basePath, uda.value.data);
}
}
URL bu = this.settings.baseURL;
bu.pathString = this.basePath;
this.baseURL = bu.toString();

if (this.settings.baseURL != URL.init)
{
URL bu = this.settings.baseURL;
bu.pathString = this.basePath;
this.baseURL = bu.toString();
}
else this.baseURL = this.basePath;

computeRoutes();
computeSubInterfaces();
Expand Down
7 changes: 7 additions & 0 deletions web/vibe/web/rest.d
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,12 @@ HTTPServerRequestDelegate serveRestJSClient(I)(string base_url)
settings.baseURL = URL(base_url);
return serveRestJSClient!I(settings);
}
/// ditto
HTTPServerRequestDelegate serveRestJSClient(I)()
{
auto settings = new RestInterfaceSettings;
return serveRestJSClient!I(settings);
}

///
unittest {
Expand All @@ -524,6 +530,7 @@ unittest {
router.get("/myapi.js", serveRestJSClient!MyAPI(restsettings));
//router.get("/myapi.js", serveRestJSClient!MyAPI(URL("http://api.example.org/")));
//router.get("/myapi.js", serveRestJSClient!MyAPI("http://api.example.org/"));
//router.get("/myapi.js", serveRestJSClient!MyAPI()); // if want to request to self server
//router.get("/", staticTemplate!"index.dt");

listenHTTP(new HTTPServerSettings, router);
Expand Down