raco pkg: GitHub API now requires a User-Agent

Merge to v5.3.4
(cherry picked from commit 9d43fcad3e)
This commit is contained in:
Matthew Flatt 2013-04-26 07:33:21 -06:00 committed by Ryan Culpepper
parent 2fea9c36fc
commit 861ef7f721
2 changed files with 10 additions and 6 deletions

View File

@ -48,8 +48,6 @@
(for/list ([v (in-list l)])
(format "\n ~a" v)))))
(define-logger pkg)
(define (log-exn x what)
(log-pkg-error (~a "failure ~a\n"
" error: ~s")

View File

@ -8,6 +8,8 @@
net/url
json)
(define-logger pkg)
(define (make-parent-directory* p)
(define parent (path-only p))
(make-directory* parent))
@ -28,9 +30,11 @@
(make-string (+ (- width (string-length col)) 4) #\space))))
(printf "\n")))
(define (call/input-url+200 u fun)
(define (call/input-url+200 u fun #:headers [headers '()])
#;(printf "\t\tReading ~a\n" (url->string u))
(define-values (ip hs) (get-pure-port/headers u #:redirections 25 #:status? #t))
(define-values (ip hs) (get-pure-port/headers u headers
#:redirections 25
#:status? #t))
(and (string=? "200" (substring hs 9 12))
(fun ip)))
@ -56,10 +60,12 @@
(list "repos" user repo "branches"))
query
#f))
(log-pkg-debug "Querying GitHub at ~a" (url->string api-u))
(define api-bs
(call/input-url+200 api-u port->bytes))
(call/input-url+200 api-u port->bytes
#:headers (list (format "User-Agent: raco-pkg/~a" (version)))))
(unless api-bs
(error 'package-url->checksum
(error 'package-url->checksum
"Could not connect to GitHub"))
(define branches
(read-json (open-input-bytes api-bs)))