diff --git a/source/dub/packagesuppliers/registry.d b/source/dub/packagesuppliers/registry.d index 3eb2c88..546dac0 100644 --- a/source/dub/packagesuppliers/registry.d +++ b/source/dub/packagesuppliers/registry.d @@ -63,7 +63,7 @@ } catch(HTTPStatusException e) { if (e.status == 404) throw e; - else logDebug("Failed to download package %s from %s", packageId, url); + else logDebug("Failed to download package %s from %s", packageId, url); } catch(Exception e) { logDebug("Failed to download package %s from %s", packageId, url); @@ -86,7 +86,7 @@ m_metadataCache.remove(packageId); } - auto url = m_registryUrl ~ NativePath(PackagesPath ~ "/" ~ packageId ~ ".json"); + auto url = m_registryUrl ~ NativePath("api/packages/" ~ packageId ~ "/info?minimize=true"); logDebug("Downloading metadata for %s", packageId); string jsonData; @@ -102,9 +102,6 @@ } Json json = parseJsonString(jsonData, url.toString()); - // strip readme data (to save size and time) - foreach (ref v; json["versions"]) - v.remove("readme"); m_metadataCache[packageId] = CacheEntry(json, now); return json; } diff --git a/test/issue1336-registry/api/packages/gitcompatibledubpackage/info__minimize=true b/test/issue1336-registry/api/packages/gitcompatibledubpackage/info__minimize=true new file mode 100644 index 0000000..6f0d641 --- /dev/null +++ b/test/issue1336-registry/api/packages/gitcompatibledubpackage/info__minimize=true @@ -0,0 +1 @@ +{"repository":{"project":"gitcompatibledubpackage","owner":"dlang-community","kind":"github"},"dateAdded":"2017-02-11T21:00:16","name":"gitcompatibledubpackage","categories":[],"owner":"5148973d2179ddb20b0002fd","id":"589f6d501c18646d0ee49f12","versions":[{"packageDescriptionFile":"dub.sdl","configurations":[{"name":"exe","targetType":"executable","mainSourceFile":"hello.d"},{"excludedSourceFiles":["hello.d"],"name":"lib","targetType":"library"}],"commitID":"9e3972be4c63790c32257220f40c0af7dc41bec5","importPaths":[".."],"name":"gitcompatibledubpackage","version":"~master","license":"public domain","readmeFile":"/README.md","date":"2017-09-18T18:18:35Z","description":"Example of a DUB package also usable as git submodule. For DUB test suite.","sourcePaths":["."]},{"packageDescriptionFile":"dub.json","commitID":"b62466d32dd6bbb0d45f9a73c91142205d1048e5","importPaths":[".."],"name":"gitcompatibledubpackage","version":"1.0.1","license":"public domain","readmeFile":"/README.md","date":"2015-10-31T11:09:14Z","description":"Example of a DUB package also usable as git submodule. For DUB test suite."},{"packageDescriptionFile":"dub.json","commitID":"cef89b5513a140b1e3417809f59d1957ddaad837","importPaths":[".."],"name":"gitcompatibledubpackage","version":"1.0.2","license":"public domain","readmeFile":"/README.md","date":"2015-10-31T11:23:53Z","description":"Example of a DUB package also usable as git submodule. For DUB test suite.","sourcePaths":["."]},{"packageDescriptionFile":"dub.json","commitID":"d36e49d31b26ea76e1670e9d5cd89aaac40fde75","importPaths":[".."],"name":"gitcompatibledubpackage","version":"1.0.3","targetType":"executable","license":"public domain","readmeFile":"/README.md","date":"2017-04-05T22:12:48Z","description":"Example of a DUB package also usable as git submodule. For DUB test suite.","mainSourceFile":"hello.d","sourcePaths":["."]},{"packageDescriptionFile":"dub.sdl","configurations":[{"name":"exe","targetType":"executable","mainSourceFile":"hello.d"},{"excludedSourceFiles":["hello.d"],"name":"lib","targetType":"library"}],"commitID":"9e3972be4c63790c32257220f40c0af7dc41bec5","importPaths":[".."],"name":"gitcompatibledubpackage","version":"1.0.4","license":"public domain","readmeFile":"/README.md","date":"2017-09-18T18:18:35Z","description":"Example of a DUB package also usable as git submodule. For DUB test suite.","sourcePaths":["."]}]} \ No newline at end of file diff --git a/test/issue1336-registry/packages/gitcompatibledubpackage.json b/test/issue1336-registry/packages/gitcompatibledubpackage.json deleted file mode 100644 index 6f0d641..0000000 --- a/test/issue1336-registry/packages/gitcompatibledubpackage.json +++ /dev/null @@ -1 +0,0 @@ -{"repository":{"project":"gitcompatibledubpackage","owner":"dlang-community","kind":"github"},"dateAdded":"2017-02-11T21:00:16","name":"gitcompatibledubpackage","categories":[],"owner":"5148973d2179ddb20b0002fd","id":"589f6d501c18646d0ee49f12","versions":[{"packageDescriptionFile":"dub.sdl","configurations":[{"name":"exe","targetType":"executable","mainSourceFile":"hello.d"},{"excludedSourceFiles":["hello.d"],"name":"lib","targetType":"library"}],"commitID":"9e3972be4c63790c32257220f40c0af7dc41bec5","importPaths":[".."],"name":"gitcompatibledubpackage","version":"~master","license":"public domain","readmeFile":"/README.md","date":"2017-09-18T18:18:35Z","description":"Example of a DUB package also usable as git submodule. For DUB test suite.","sourcePaths":["."]},{"packageDescriptionFile":"dub.json","commitID":"b62466d32dd6bbb0d45f9a73c91142205d1048e5","importPaths":[".."],"name":"gitcompatibledubpackage","version":"1.0.1","license":"public domain","readmeFile":"/README.md","date":"2015-10-31T11:09:14Z","description":"Example of a DUB package also usable as git submodule. For DUB test suite."},{"packageDescriptionFile":"dub.json","commitID":"cef89b5513a140b1e3417809f59d1957ddaad837","importPaths":[".."],"name":"gitcompatibledubpackage","version":"1.0.2","license":"public domain","readmeFile":"/README.md","date":"2015-10-31T11:23:53Z","description":"Example of a DUB package also usable as git submodule. For DUB test suite.","sourcePaths":["."]},{"packageDescriptionFile":"dub.json","commitID":"d36e49d31b26ea76e1670e9d5cd89aaac40fde75","importPaths":[".."],"name":"gitcompatibledubpackage","version":"1.0.3","targetType":"executable","license":"public domain","readmeFile":"/README.md","date":"2017-04-05T22:12:48Z","description":"Example of a DUB package also usable as git submodule. For DUB test suite.","mainSourceFile":"hello.d","sourcePaths":["."]},{"packageDescriptionFile":"dub.sdl","configurations":[{"name":"exe","targetType":"executable","mainSourceFile":"hello.d"},{"excludedSourceFiles":["hello.d"],"name":"lib","targetType":"library"}],"commitID":"9e3972be4c63790c32257220f40c0af7dc41bec5","importPaths":[".."],"name":"gitcompatibledubpackage","version":"1.0.4","license":"public domain","readmeFile":"/README.md","date":"2017-09-18T18:18:35Z","description":"Example of a DUB package also usable as git submodule. For DUB test suite.","sourcePaths":["."]}]} \ No newline at end of file diff --git a/test/test_registry.d b/test/test_registry.d old mode 100644 new mode 100755 index dfeb358..f5d14c1 --- a/test/test_registry.d +++ b/test/test_registry.d @@ -1,11 +1,42 @@ +#!/usr/bin/env dub /+dub.sdl: -dependency "vibe-d" version="~>0.8.3-alpha.1" +dependency "vibe-d" version="~>0.8.5" versions "VibeNoSSL" +/ +import vibe.d; + +/* +Provide a special API File Handler as Vibe.d's builtin serveStaticFiles +doesn't deal well with query params. +This will blindly check if the requestURI payload exists on the filesystem and if so, return the file. + +It replaces `?` with `__` for Windows compatibility. + +Params: + skip = initial part of the requestURI to skip over + folder = the base directory from which to serve API requests from +*/ +auto apiFileHandler(string skip, string folder) { + import std.functional : toDelegate; + void handler(HTTPServerRequest req, HTTPServerResponse res) { + import std.algorithm : skipOver; + import std.path : buildPath; + import std.file : exists; + // ? can't be part of path names on Windows + auto requestURI = req.requestURI.replace("?", "__"); + requestURI.skipOver(skip); + const reqFile = buildPath(folder, requestURI); + if (reqFile.exists) { + return req.sendFile(res, PosixPath(reqFile)); + } + } + return toDelegate(&handler); +} + void main(string[] args) { - import std.conv, vibe.d; + import std.conv; immutable folder = readRequiredOption!string("folder", "Folder to service files from."); immutable port = readRequiredOption!uint("port", "Port to use"); auto router = new URLRouter; @@ -18,6 +49,8 @@ }); router.get("*", folder.serveStaticFiles); router.get("/fallback/*", folder.serveStaticFiles(new HTTPFileServerSettings("/fallback"))); + router.get("/api/*", apiFileHandler("/", folder)); + router.get("/fallback/api/*", apiFileHandler("/fallback/", folder)); listenHTTP(text(":", port), router); runApplication(); }