guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: issue with SWH ratelimit (authorization via HTTP header)


From: zimoun
Subject: Re: issue with SWH ratelimit (authorization via HTTP header)
Date: Thu, 14 Oct 2021 21:01:15 +0200

Hi,

Thanks to Ricardo on #guix-hpc, the issue is:

    `((authorization . (Bearer ,token))))

and not ’bearer’.  Maybe the process can help.

It is misleading because the documentation [1] says to use:

--8<---------------cut here---------------start------------->8---
Enter `,help' for help.
scheme@(guix-user)> ,use(web http)
scheme@(guix-user)> (parse-header 'authorization "Bearer eyJh…")
$1 = (bearer eyJh…)
--8<---------------cut here---------------end--------------->8---

But it is not what

    (http-request URL #:method 'POST #:headers `((authorization . (bearer 
,token))))

returns.

Let open a terminal and run ’emacs-simple-httpd’ as server.  The buffer
*httpd* lists what is happening.  In another terminal, let run the
request above.  Tadam!

--8<---------------cut here---------------start------------->8---
(request
 (date "Thu, 14 Oct 2021 18:41:51 GMT")
 (address "127.0.0.1")
 (get "/")
 (headers
  ("POST" "/" "HTTP/1.1")
  ("Host" "localhost:8080")
  ("Connection" "close")
  ("Authorization" "Bearer eyJh…$
  ("Content" ""))
--8<---------------cut here---------------end--------------->8---

Now, with the correct header, it works:

--8<---------------cut here---------------start------------->8---
scheme@(guix-user)> ,use(web client)
scheme@(guix-user)> (http-request 
"https://archive.softwareheritage.org/api/1/stat/counters/"; #:method 'POST 
#:headers `((authorization . (Bearer ,token))))
$2 = #<<response> version: (1 . 1) code: 405 reason-phrase: "Method Not 
Allowed" headers: ((date . #<date nanosecond: 0 second: 2 minute: 59 hour: 18 
day: 14 month: 10 year: 2021 zone-offset: 0>) (server . "gunicorn/19.9.0") 
(content-type application/json) (vary accept cookie) (allow GET OPTIONS HEAD 
OPTIONS) (x-ratelimit-limit . "1200") (x-ratelimit-remaining . "137") 
(x-ratelimit-reset . "1634237954") (x-frame-options . "SAMEORIGIN") 
(content-length . 72) (via "1.1 archive.softwareheritage.org") (x-varnish . 
"35772607") (age . 0) (via "1.1 varnish (Varnish/6.1)") 
(strict-transport-security . "max-age=15768000;") (connection close)) port: 
#<closed: file 7f624e3f51c0>>
$4 = #vu8(123 34 101 120 99 101 112 116 105 111 110 34 58 34 77 101 116 104 111 
100 78 111 116 65 108 108 111 119 101 100 34 44 34 114 101 97 115 111 110 34 58 
34 77 101 116 104 111 100 32 92 34 80 79 83 84 92 34 32 110 111 116 32 97 108 
108 111 119 101 100 46 34 125)
--8<---------------cut here---------------end--------------->8---


Cheers,
simon

1: <https://www.gnu.org/software/guile/manual/html_node/HTTP-Headers.html>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]