Skip to content

Latest commit

 

History

History
36 lines (36 loc) · 3.44 KB

2.0-changes.md

File metadata and controls

36 lines (36 loc) · 3.44 KB

To migrate from legacy versions of WebHost (Or Guavacado 1.X) to Guavacado 2.0, the following considerations must be made:

  • guavacado.WebHost.start_service() no longer blocks indefinitely. Instead, it spawns a new thread for each port that is open, then returns. If your app previously relied on guavacado.WebHost.start_service() blocking indefinitely, you can call guavacado.wait_for_keyboardinterrupt() to efficiently block until Ctrl+C is pressed in the terminal.
  • Please note that while guavacado.WebInterface can still be inherited, it is now encouraged to instead instantiate it as a member variable of your class, as follows:
class MyInterface(object):
	def __init__(self):
		self.host = guavacado.WebHost() # note this will be automatically instantiated in WebInterface if not passed in as an argument
		self.host.add_addr()
		self.interface = guavacado.WebInterface(host=self.host)
		self.interface.connect('/test/',self.GET_TEST,'GET')
	def GET_TEST(self):
		return "Test"
  • guavacado.WebInterface now requires the __init__() constructor to run. If your class inherits from guavacado.WebInterface, make sure that it calls WebInterface.__init__() in its own __init__() method. An example inherited implementation follows:
class MyInterface(guavacado.WebInterface):
	def __init__(self):
		self.host = guavacado.WebHost() # note this will be automatically instantiated in WebInterface if not set here before calling __init__()
		self.host.add_addr()
		guavacado.WebInterface.__init__(self)
		self.connect('/test/',self.GET_TEST,'GET')
	def GET_TEST(self):
		return "Test"
  • The addr and port arguments to guavacado.WebHost's constructor have now been removed. This functionality is now replaced by the add_addr() method of guavacado.WebHost, which accepts the same optional arguments, along with an optional TLS argument to provide a tuple of the filenames of the certfile and keyfile for HTTPS. While omitting the call to add_addr() will default to HTTP on port 80, this will result in a warning, and it is discouraged to rely on this default functionality.
  • Guavacado 2.0 now supports HTTPS (HTTP through TLS) and automatic redirection from HTTP to HTTPS. An HTTPS interface can be implemented with add_addr(port=443, TLS=('TLS_keys/certfile.crt', 'TLS_keys/keyfile.key')) after creating a certificate and key, stored in TLS_keys/certfile.crt and TLS_keys/keyfile.key, respectively. Self-signed keys can be generated by the script tls_keygen.sh, or a signed key for a public server can be obtained from a certificate authority, such as Let's Encrypt, that is trusted by most browsers. When using HTTPS, you can also easily redirect HTTP traffic to the equivalent HTTPS page with add_addr(port=80, disp_type=('redirect', 'https://domain/')), (with domain replaced with your domain name).
  • guavacado.WebHost no longer hosts the 'static' directory by default. You must now manually instantiate guavacado.WebFileInterface to host a directory. This allows for implementation of REST APIs without enabling direct file access when that feature is not needed. Example "files only" implementation:
host = guavacado.WebHost(loglevel='INFO')
host.add_addr(port=80, disp_type=('redirect', 'https://domain/'))
host.add_addr(port=443, TLS=('TLS_keys/certfile.crt', 'TLS_keys/keyfile.key'))
files = guavacado.WebFileInterface(host)
host.start_service()
wait_for_keyboardinterrupt()
host.stop_service()