[racket] retrieving an https url

From: Greg Hendershott (greghendershott at gmail.com)
Date: Wed Jun 22 09:27:46 EDT 2011

At first I thought you meant users would need to set this parameter
each time. Then I looked on GitHub.com and found this:

;; make-ports : url -> in-port x out-port
(define (make-ports url proxy)
  (let ([port-number (if proxy
                       (caddr proxy)
                       (or (url-port url) (url->default-port url)))]
        [host (if proxy (cadr proxy) (url-host url))])
    (parameterize ([current-connect-scheme (url-scheme url)])
      (tcp-connect host port-number))))

IIUC, that's great: Now the X-(im)pure-port functions will just work
-- regardless of whether the URI scheme is https, explicitly http, or
implicitly http.

The lack of this before was a small speed bump for me as a Racket
newcomer. I found a blog post and ended up rewriting my own versions
of X-(im)pure-port to act as above. In my case I didn't mind the
detour too much, and I learned something from it. But it's great that
newer newcomers won't have that speed bump.

On Tue, Jun 21, 2011 at 11:39 PM, Eli Barzilay <eli at barzilay.org> wrote:
> 25 minutes ago, Greg Hendershott wrote:
>> I also agree.
>>
>> It should be a very simple change in url-unit.rkt.  The last line of
>> `make-ports' is where `tcp-connect' is hardwired: [...]
>
> Yeah, that part isn't complicated, but it was tricky to get things to
> conform to the same API it has now.  I did a hack that did that, then
> Matthew un-hacked it by a minor extension to the API (one new unit).
>
> The bottom line -- which I should have posted here but forgot -- is
> that for almost everyone (= people who just require `net/url') it just
> works for https now.  (It's also possible to install trusted certs if
> you need that level of security.)
>
>> ;; connector : url -> (string? (integer-in 1 65535) -> input-port? output-port?)
>> ;; returns either tcp-connect or ssl-connect
>> (define (connector url)
>>   (let ([scheme (url-scheme url)])
>>     (cond [(not scheme) tcp-connect]
>>           [(string=? scheme "http") tcp-connect]
>>           [(string=? scheme "https") ssl-connect]
>>           [else (url-error "Scheme ~a not supported" (url-scheme url))])))
>> [...]
>
> FWIW, the implementation adds a `current-connect-scheme' parameter
> that gets set to the scheme, then it's possible to wire in a
> `tcp-connect' that uses the tcp version or the ssl version based on
> that.
>
> --
>          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
>                    http://barzilay.org/                   Maze is Life!
>



Posted on the users mailing list.