[racket] retrieving an https url

From: Greg Hendershott (greghendershott at gmail.com)
Date: Tue Jun 21 23:09:40 EDT 2011

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:

;; 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))])
    (tcp-connect host port-number)))

The call to `tcp-connect' could be replaced with a call to a new
function that is very similar to the existing function immediately
above `make-ports', which is `url->default-port':

;; url->default-port : url -> num
(define (url->default-port url)
  (let ([scheme (url-scheme url)])
    (cond [(not scheme) 80]
          [(string=? scheme "http") 80]
          [(string=? scheme "https") 443]
          [else (url-error "Scheme ~a not supported" (url-scheme url))])))

Such new function could be e.g. `connector':

;; 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))])))

So we have the new `make-ports', that looks at the URI's scheme (if any):

;; 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))])
    ((connector url) host port-number)))


On Sat, Jun 18, 2011 at 4:53 PM, Neil Van Dyke <neil at neilvandyke.org> wrote:
> Sam Tobin-Hochstadt wrote at 06/18/2011 04:30 PM:
>>
>> I've put all of these examples up on the GitHub Racket wiki:
>>  https://github.com/plt/racket/wiki/HTTP-over-SSL
>>
>> Hopefully, that will be a useful reference the next time someone asks
>> about SSL.
>>
>
> HTTPS support should *really*, *really* be in Racket out of the box, so that
> "get-pure-port" and friends do the right thing whether it's HTTP or HTTPS.
>
> No more sending users on wild goose chases through official manuals, and
> multiple wikis, and Googling through four different duplicate archives of
> the email list.
>
> --
> http://www.neilvandyke.org/
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users
>



Posted on the users mailing list.