@@ -22,13 +22,25 @@ HttpBinaryCacheStoreConfig::HttpBinaryCacheStoreConfig(
2222 std::string_view scheme, std::string_view _cacheUri, const Params & params)
2323 : StoreConfig(params)
2424 , BinaryCacheStoreConfig(params)
25- , cacheUri(
25+ , cacheUri(parseURL(
2626 std::string{scheme} + " ://"
2727 + (!_cacheUri.empty() ? _cacheUri
28- : throw UsageError (" `%s` Store requires a non-empty authority in Store URL" , scheme)))
28+ : throw UsageError (" `%s` Store requires a non-empty authority in Store URL" , scheme))))
2929{
30- while (!cacheUri.empty () && cacheUri.back () == ' /' )
31- cacheUri.pop_back ();
30+ while (!cacheUri.path .empty () && cacheUri.path .back () == ' /' )
31+ cacheUri.path .pop_back ();
32+ }
33+
34+ StoreReference HttpBinaryCacheStoreConfig::getReference () const
35+ {
36+ return {
37+ .variant =
38+ StoreReference::Specified{
39+ .scheme = cacheUri.scheme ,
40+ .authority = (cacheUri.authority ? cacheUri.authority ->to_string () : " " ) + cacheUri.path ,
41+ },
42+ .params = cacheUri.query ,
43+ };
3244}
3345
3446std::string HttpBinaryCacheStoreConfig::doc ()
@@ -65,16 +77,17 @@ class HttpBinaryCacheStore : public virtual BinaryCacheStore
6577 void init () override
6678 {
6779 // FIXME: do this lazily?
68- if (auto cacheInfo = diskCache->upToDateCacheExists (config->cacheUri )) {
80+ if (auto cacheInfo = diskCache->upToDateCacheExists (config->cacheUri . to_string () )) {
6981 config->wantMassQuery .setDefault (cacheInfo->wantMassQuery );
7082 config->priority .setDefault (cacheInfo->priority );
7183 } else {
7284 try {
7385 BinaryCacheStore::init ();
7486 } catch (UploadToHTTP &) {
75- throw Error (" '%s' does not appear to be a binary cache" , config->cacheUri );
87+ throw Error (" '%s' does not appear to be a binary cache" , config->cacheUri . to_string () );
7688 }
77- diskCache->createCache (config->cacheUri , config->storeDir , config->wantMassQuery , config->priority );
89+ diskCache->createCache (
90+ config->cacheUri .to_string (), config->storeDir , config->wantMassQuery , config->priority );
7891 }
7992 }
8093
@@ -134,16 +147,29 @@ class HttpBinaryCacheStore : public virtual BinaryCacheStore
134147 try {
135148 getFileTransfer ()->upload (req);
136149 } catch (FileTransferError & e) {
137- throw UploadToHTTP (" while uploading to HTTP binary cache at '%s': %s" , config->cacheUri , e.msg ());
150+ throw UploadToHTTP (
151+ " while uploading to HTTP binary cache at '%s': %s" , config->cacheUri .to_string (), e.msg ());
138152 }
139153 }
140154
141155 FileTransferRequest makeRequest (const std::string & path)
142156 {
157+ /* FIXME path is not a path, but a full relative or absolute
158+ URL, e.g. we've seen in the wild NARINFO files have a URL
159+ field which is
160+ `nar/15f99rdaf26k39knmzry4xd0d97wp6yfpnfk1z9avakis7ipb9yg.nar?hash=zphkqn2wg8mnvbkixnl2aadkbn0rcnfj`
161+ (note the query param) and that gets passed here.
162+
163+ What should actually happen is that we have two parsed URLs
164+ (if we support relative URLs), and then we combined them with
165+ a URL `operator/` which would be like
166+ `std::filesystem::path`'s equivalent operator, which properly
167+ combines the the URLs, whether the right is relative or
168+ absolute. */
143169 return FileTransferRequest (
144170 hasPrefix (path, " https://" ) || hasPrefix (path, " http://" ) || hasPrefix (path, " file://" )
145171 ? path
146- : config->cacheUri + " /" + path);
172+ : config->cacheUri . to_string () + " /" + path);
147173 }
148174
149175 void getFile (const std::string & path, Sink & sink) override
0 commit comments