[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: issue with SWH ratelimit (authorization via HTTP header)
From: |
Maxim Cournoyer |
Subject: |
Re: issue with SWH ratelimit (authorization via HTTP header) |
Date: |
Fri, 15 Oct 2021 12:29:06 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) |
Hello,
zimoun <zimon.toutoune@gmail.com> writes:
> 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:
>
> Enter `,help' for help.
> scheme@(guix-user)> ,use(web http)
> scheme@(guix-user)> (parse-header 'authorization "Bearer eyJh…")
> $1 = (bearer eyJh…)
>
>
> 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!
>
> (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" ""))
>
>
> Now, with the correct header, it works:
>
> 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)
Cool debugging session!
Thanks for sharing,
Maxim