OILS / demo / https.sh View on Github | oils.pub

106 lines, 43 significant
1#!/usr/bin/env bash
2#
3# Testing how to send requests without curl
4#
5# Client features
6#
7# - SSL, for HTTPS
8# - Connection: Keep-Alive, for latency
9# - Timeouts, for robustness
10# - Client side redirects
11# - Sending arbitrary headers, for auth
12# - Encoding: URL encoding, multi-part/MIME
13# - It would be nice to offload this encoding, similar to how CGI v2 offloads
14# parsing
15# - Large streaming uploasd and downloads - this might need to be a separate
16# request, e.g. to the wwup process
17#
18# Probably don't care about:
19# - HTTP Cache - we might have a different mechanism - this is very complex and
20# "best effort"
21# - or there can be local cache of the "Oils SQL Waist"
22# - Cookies? Not sure
23#
24# Not sure:
25# - Proxy support
26
27with-openssl() {
28 # Hm, it works for google.com, yahoo, HN, dreamhost.com/
29 #
30 # But Dreamhost shared hosting doesn't like it for some reason - get 400
31 # error
32 local hostname=${1:-www.google.com}
33
34 #openssl s_client -connect $hostname:443 <<EOF
35 openssl s_client -connect $hostname:443 -quiet <<EOF
36GET / HTTP/1.1
37Host: $hostname
38
39EOF
40}
41
42get-home() {
43 local hostname=${1:-oils.pub}
44 printf 'GET / HTTP/1.1\r\nHost: %s\r\n\r\n' "$hostname"
45}
46
47# Hm this works, the \r\n does matter.
48crlf() {
49 local hostname=${1:-oils.pub}
50 get-home "$hostname" |
51 openssl s_client -connect $hostname:443 -quiet
52}
53
54with-curl() {
55 curl -v --include https://oils.pub/ |head
56}
57
58# TODO:
59# - HTTPS
60# - socat
61# - BoringSSL has 's_client' I guess
62# - for plain HTTP
63# - nc
64# - telnet
65
66deps() {
67 sudo apt-get install socat
68}
69
70with-socat() {
71 # This closes the pipe
72 local hostname=${1:-mb.oils.pub}
73 time get-home "$hostname" |
74 socat - openssl:$hostname:443
75}
76
77with-socat-http() {
78 # This closes the pipe
79 local hostname=${1:-mb.oils.pub}
80 time get-home "$hostname" |
81 socat - tcp:$hostname:80
82}
83
84
85with-socat-2() {
86 # This sorta works
87 local hostname=${1:-mb.oils.pub}
88
89 { get-home "mb.oils.pub";
90 get-home "mb.oils.pub";
91 } | socat - openssl:$hostname:443,fork
92}
93
94with-telnet() {
95 # Hm doesn't work
96 local hostname=${1:-mb.oils.pub}
97 time get-home "$hostname" | telnet $hostname 80
98}
99
100with-nc() {
101 # Hm doesn't work
102 local hostname=${1:-mb.oils.pub}
103 time get-home "$hostname" | nc $hostname 80
104}
105
106"$@"