s c h e m a t i c s : c o o k b o o k

/ Cookbook.WebFetchingHttpsUrl

This Web


WebHome 
WebChanges 
TOC (with recipes)
NewRecipe 
WebTopicList 
WebStatistics 

Other Webs


Chicken
Cookbook
Erlang
Know
Main
Plugins
Sandbox
Scm
TWiki  

Schematics


Schematics Home
Sourceforge Page
SchemeWiki.org
Original Cookbook
RSS

Scheme Links


Schemers.org
Scheme FAQ
R5RS
SRFIs
Scheme Cross Reference
PLT Scheme SISC
Scheme48 SCM
MIT Scheme scsh
JScheme Kawa
Chicken Guile
Bigloo Tiny
Gambit LispMe
GaucheChez

Lambda the Ultimate
TWiki.org

Fetching an HTTPS URL

Problem

PLT Scheme's url.ss library in the net collection does not directly support retrieval of URLs via HTTPS, i.e. using SSL.

Solution

PLT's unit system can be used to create a version of the url module which does support HTTPS URLs. Place the following code in a file called e.g. ssl-url.scm:

;; From Eli Barzilay

#lang scheme

;; This will give us ssl:--- for an ssl version of url.ss, but still need an
;; explicit port number specification since url.ss does not handle that
(require scheme/unit
         net/url-sig net/url-unit
         net/tcp-sig net/tcp-unit
         net/ssl-tcp-unit)
(define-values/invoke-unit
  (compound-unit/infer (import) (export url^) (link tcp@ url@))
  (import) (export url^))
(define ssl-tcp@ (make-ssl-tcp@ #f #f #f #f #f #f #f))
(define-values/invoke-unit
  (compound-unit (import) (export URL)
    (link [((TCP : tcp^)) ssl-tcp@]
          [((URL : url^)) url@ TCP]))
  (import) (export (prefix ssl: url^)))
(provide (all-defined-out))

You can then require this module using (require "ssl-url.scm"), and use the standard url API described in WebFetchingURL to retrieve HTTPS URLs.

Discussion

This works by essentially creating a clone of PLT's url.ss module, and linking it with ssl-tcp-unit.ss instead of tcp-unit.ss. The above code is simply a copy of url.ss with the relevant details changed.

Note that a module which uses the above module can only fetch SSL URLs. Regular HTTP URLs can be fetched by requiring the original url.ss. A module which needs to fetch both types of URL can do so by applying a prefix to the names of one of the modules, for example:

(require (prefix ssl: "ssl-url.scm"))

...and then use procedure names like ssl:get-pure-port to retrieve SSL URLs.

Also note that this still supports http:// URLs only. You will need to translate https://foo.com/... to http://foo.com:443/... (in case it doesn't have a port).

Comments

This code was based on an example provided by Noel Welsh.

-- AntonVanStraaten - 29 Nov 2005

Ergo, Anton is a hero.

-- NoelWelsh - 01 Dec 2005

Updated for PLT v370.

-- DaveGurnell - 31 May 2007

I needed to change "unitsig.ss" to "unit.ss" to work in v371. I'd change the code but how to do that is not clear. :-P

-- PeteHopkins - 04 Sep 2007

I've edited the code. Some source is stored separately in the Scm web with the intent of being able to easily produce a collection of source from the Cookbook. Not that producing such a collection has actually been done, but it could be. Easily. :)

-- AntonVanStraaten - 05 Sep 2007

Here's an example of its use:

#lang scheme
(require "ssl-url.ss")

(ssl:call/input-url
 (string->url "https://www.amazon.com/")
 ssl:get-impure-port
 (lambda (ip)
   (fprintf (current-error-port) "Look out, nellie!!~%")
   (copy-port ip (current-output-port))))

-- EricHanchrow - 17 Dec 2008

CookbookForm
TopicType: Recipe
ParentTopic: WebRecipes
TopicOrder: 012

 
 
Copyright © 2004 by the contributing authors. All material on the Schematics Cookbook web site is the property of the contributing authors.
The copyright for certain compilations of material taken from this website is held by the SchematicsEditorsGroup - see ContributorAgreement & LGPL.
Other than such compilations, this material can be redistributed and/or modified under the terms of the GNU Lesser General Public License (LGPL), version 2.1, as published by the Free Software Foundation.
Ideas, requests, problems regarding Schematics Cookbook? Send feedback.
/ You are Main.guest