-- Leo's gemini proxy

-- Connecting to going-flying.com:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini; lang=en

[09/01/2020 @19:45]: An RFC proxy


Just a quick note. I updated the post I wrote the other day wondering if the late adoption of IPv6 helped push adoption of the cloud-as-a-middleman use case to use a small proxy script I wrote. The script proxies to the IETF's web site and fetches the plain text version of an RFC. It seemed silly to make the reader refer to HTTPS urls of plain text documents while reading a Gemini document.



Did the slow adoption of IPv6 lead to the cloud?



If you are interested you can retrieve any valid RFC from the IETF by simply passing the plain text file name to the script. If you are interested the script is below.


#!/usr/bin/env python3
''' rfc (c) 2020 Matthew J Ernisse <matt@going-flying.com>
All Rights Reserved.

Redistribution and use in source and binary forms,
with or without modification, are permitted provided
that the following conditions are met:

    * Redistributions of source code must retain the
      above copyright notice, this list of conditions
      and the following disclaimer.
    * Redistributions in binary form must reproduce
      the above copyright notice, this list of conditions
      and the following disclaimer in the documentation
      and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
'''
import os
import re
import requests
import sys

def check_requested_path():
	''' Molly Brown sends us the rest of the requested url on stdin, so
	read that and check to make sure it is a request for an RFC.
	'''
	rfc = os.environ.get('PATH_INFO')
	if not rfc:
		raise ValueError('No RFC requested.')

	matches = re.search(r'^rfc\d+\.txt', rfc)
	if not matches:
		raise ValueError('Request must be a RFC text file.')

	return rfc


def get_rfc(rfc):
	''' Return the text contents of an RFC. '''
	resp = requests.get(
		f'https://tools.ietf.org/rfc/{rfc}',
		headers={
			'User-Agent': 'gemini-rfc-proxy/matt@going-flying.com'
		}
	)

	resp.raise_for_status()
	return resp.text


if __name__ == "__main__":
	try:
		rfc = check_requested_path()
		body = get_rfc(rfc)
	except ValueError as e:
		print(f'59 {str(e)}\r\n')
		sys.exit()

	except requests.exceptions.HTTPError as e:
		if e.errno == 404:
			print(f'51 Not Found.\r\n')
			sys.exit()

		elif e.errno > 399 and e.errno < 500:
			print(f'43 {e.strerror}\r\n')
			sys.exit()
		else:
			print(f'53 {e.strerror}\r\n')
			sys.exit()

	print('20 text/plain\r\n')
	print(body)





↩ back to index

backlinks [GUS]

backlinks [geminispace.info]


🚀 © MMXX-MMXXI matt@going-flying.com

-- Response ended

-- Page fetched on Tue Sep 21 07:38:56 2021