This page permanently redirects to gemini://going-flying.com/git/cgi/gemini.git/tree/ac059d8cec96a23a94e3fb54bfcd6a780044602e/cgi-bin/rfc.
=> going-flying.com gemini git repository
=> summary
=> tree
=> log
=> refs
=> view raw
#!/usr/bin/env python3 ''' rfc (c) 2020 Matthew J ErnisseAll 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)
text/gemini
This content has been proxied by September (ba2dc).