SstHttpClientExample
Tip icon
This section describes SstHttp11ClientExample, which is a minimal HTTP client which you can use to bash your favorite web server and repeatedly fetch URLs. Try running the example, substituting your own target URLs, as shown below:
SstHttp11ClientExample
exampleWith: #('http://foo.com:80/')
bash: 5
You will get an inspector on an OrderedCollection of response records, where each such record contains the millisecond roundtrip time for the request and the actual HTTP response content for the request. The example also prints out some simple statistics to the SystemTranscript.
This example illustrates the essential procedure for an SST transport client:
1. Create and start a client endpoint
2. Create a target remote endpoint
3. Create a transport message
4. Have the local endpoint send the transport message to the remote endpoint
5. Wait on the local endpoint for a response from the remote endpoint
6. Shut down the local endpoint
There are a number of legitimate variations of the sort of scenario represented by this example, but the essentials are all the same.
This example uses an HTTP/1.1 persistent connection. All bash iterations use the same connection and are serialized. The SstHttpClientExample uses HTTP/1.0 with connection-per-request, and models a multithreaded application which is concurrently fetching web pages from various servers.
The SstHttpClientExample is particularly interesting by way of demonstrating the use of SstExplicitFutures and discrimintated SstRemoteEndpoints to associate a reply with one of several known outstanding requests.
The class SstHttpUrl provides an HTTP/1.0 client, in the form of SstHttpUrl>>fetch and SstHttpUrl>>post:, which sets up and tears down an HTTP endpoint on each request. This client will exploit a configured HTTP proxy. To setup a proxy directive, set the #proxyUrl on the transport configuration registered as 'httpl'.
(SstTransport configurationRegistry at: 'httpl')
proxyUrl: ('http://proxy.myco.com:8080') sstAsUrl.
With this directive in place, a message expression like the following will cause the HTTP client provided by SstHttpUrl to connect to the proxy rather than the host specified in the URL.
'http://www.foo.com/index.html' sstAsUrl fetch
Last modified date: 04/21/2020