net/url: avoid failure on bad proxy environment variable
Related to #2663
This commit is contained in:
parent
6381e3c009
commit
8c652de835
11
pkgs/net-test/tests/net/bad-proxy-envvar.rkt
Normal file
11
pkgs/net-test/tests/net/bad-proxy-envvar.rkt
Normal file
|
@ -0,0 +1,11 @@
|
|||
#lang racket/base
|
||||
(parameterize ([current-environment-variables
|
||||
(environment-variables-copy
|
||||
(current-environment-variables))]
|
||||
[current-namespace (make-base-namespace)]
|
||||
[current-logger (make-logger)])
|
||||
;; There are not a lot of strings that `url->string` rejects, but
|
||||
;; this one of them:
|
||||
(putenv "http_proxy" "http://example.com:8080 ")
|
||||
;; Dynamic load so that we get to change the logger first
|
||||
((dynamic-require 'net/url 'current-proxy-servers)))
|
|
@ -29,6 +29,12 @@
|
|||
"https"
|
||||
"git"))
|
||||
|
||||
;; Like `string->url`, but returns #f for an error, intended for use
|
||||
;; with pattern matching.
|
||||
(define (string->url* str)
|
||||
(with-handlers ([url-exception? (lambda (exn) #f)])
|
||||
(string->url str)))
|
||||
|
||||
;; env->c-p-s-entries: (listof (listof string)) -> (listof (list string string num))
|
||||
;;
|
||||
;; "http" protocol is proxied by http proxy
|
||||
|
@ -41,11 +47,11 @@
|
|||
(match (getenv envvar)
|
||||
[#f #f]
|
||||
["" null]
|
||||
[(app string->url
|
||||
[(app string->url*
|
||||
(url (and proxying-scheme "http") #f (? string? host) (? integer? port)
|
||||
_ (list) (list) #f))
|
||||
(list (list proxied-scheme host port))]
|
||||
[(app string->url
|
||||
[(app string->url*
|
||||
(url (and proxying-scheme "http") _ (? string? host) (? integer? port)
|
||||
_ _ _ _))
|
||||
(log-net/url-warning "~s contains somewhat invalid proxy URL format" envvar)
|
||||
|
|
Loading…
Reference in New Issue
Block a user