request.py 850 B

1234567891011121314151617181920212223242526272829
  1. class DaraRequest:
  2. _PROPERTY_DEFAULT_MAP = {
  3. 'query': {},
  4. 'protocol': 'http',
  5. 'port': 80,
  6. 'method': 'GET',
  7. 'headers': {},
  8. 'pathname': "",
  9. 'body': None,
  10. }
  11. def __init__(self):
  12. self.query = {}
  13. self.protocol = "http"
  14. self.port = 80
  15. self.method = "GET"
  16. self.headers = {}
  17. self.pathname = ""
  18. self.body = None
  19. def __setattr__(self, key, value):
  20. if key in self._PROPERTY_DEFAULT_MAP:
  21. if not value:
  22. if isinstance(self._PROPERTY_DEFAULT_MAP[key], (list, dict)):
  23. self.__dict__[key] = self._PROPERTY_DEFAULT_MAP[key].copy()
  24. else:
  25. self.__dict__[key] = self._PROPERTY_DEFAULT_MAP[key]
  26. return
  27. self.__dict__[key] = value