Subject: bug#44906: Substitute requests fail if URL has trailing slash

From: zimoun <[email-masked]>
Date: Sat, 28 Nov 2020 00:37:22 +0100

Dear,

Thank you for the report.

Tweaking the function such as:

--8<---------------cut here---------------start------------->8---
(define (narinfo-request cache-url path)
  "Return an HTTP request for the narinfo of PATH at CACHE-URL."
  (let ((url (string-append cache-url "/" (store-path-hash-part path)
                            ".narinfo"))
        (headers '((User-Agent . "GNU Guile"))))
    (format #t "~%Narinfo request: ~a~%~%" url)
    (build-request (string->uri url) #:method 'GET #:headers headers)))
--8<---------------cut here---------------end--------------->8---

and removing the cache adequately, then running:

--8<---------------cut here---------------start------------->8---
./pre-inst-env guix weather \
     --substitute-urls="https://ci.guix.gnu.org/ https://ci.guix.gnu.org" \
     hello
computing 1 package derivations for x86_64-linux...

looking for 1 store items on https://ci.guix.gnu.org/...

Narinfo request: https://ci.guix.gnu.org//a462kby1q51ndvxdv3b6p0rsixxrgx1h.narinfo

updating substitutes from 'https://ci.guix.gnu.org/'... 100.0%
https://ci.guix.gnu.org/
  0.0% substitutes available (0 out of 1)

[...]

  'https://ci.guix.gnu.org//api/queue?nr=1000' returned 400 ("Bad Request")

looking for 1 store items on https://ci.guix.gnu.org...

Narinfo request: https://ci.guix.gnu.org/a462kby1q51ndvxdv3b6p0rsixxrgx1h.narinfo

updating substitutes from 'https://ci.guix.gnu.org'... 100.0%
https://ci.guix.gnu.org
  100.0% substitutes available (1 out of 1)

[...]

  at least 1,000 queued builds

[...]

  build rate: 36.89 builds per hour

[...]
--8<---------------cut here---------------end--------------->8---

On Fri, 27 Nov 2020 at 22:19, Hartmut Goebel <[email-masked]> wrote:

> According to RFC 7230, sec 2.7.3 "http and https URI Normalization and
> Comparison" [1]:
>
>    […] an empty
>    path component is equivalent to an absolute path of "/", so the
>    normal form is to provide a path of "/" instead.
>
> [1] https://tools.ietf.org/html/rfc7230#section-2.7.3

Now, the question is where should the fix go?  “guix publish” exposing
the narinfos or “guix weather“?  Or both?

>From my understanding, one fix should go to ‘guix publish’ exposing the
narinfos since:

   https://ci.guix.gnu.org//a462kby1q51ndvxdv3b6p0rsixxrgx1h.narinfo

should be a valid URL and return the narinfo file.  However, taking this
road, it means that the cache folder will not be the same:

~/.cache/guix/substitute/x2wcz6gz3evwlqcrz3fqstmezkfcfnpfb5kfyxbz7kjikc7upkiq/
~/.cache/guix/substitute/4refhwxbjmeua2kwg2nmzhv4dg4d3dorpjefq7kiciw2pfhaf26a/

https://ci.guix.gnu.org/ resp. https://ci.guix.gnu.org  Therefore, ‘guix
weather’ should be fixed too.

WDYT?

All the best,
simon