extremely small and simple HTTP GET/HEAD-only web server for static content
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

56 lines
1.1 KiB

  1. /* See LICENSE file for copyright and license details. */
  2. #ifndef HTTP_H
  3. #define HTTP_H
  4. #include <limits.h>
  5. #define HEADER_MAX 4096
  6. #define FIELD_MAX 200
  7. enum req_field {
  8. REQ_HOST,
  9. REQ_RANGE,
  10. REQ_MOD,
  11. NUM_REQ_FIELDS,
  12. };
  13. extern const char *req_field_str[];
  14. enum req_method {
  15. M_GET,
  16. M_HEAD,
  17. NUM_REQ_METHODS,
  18. };
  19. extern const char *req_method_str[];
  20. struct request {
  21. enum req_method method;
  22. char target[PATH_MAX];
  23. char field[NUM_REQ_FIELDS][FIELD_MAX];
  24. };
  25. enum status {
  26. S_OK = 200,
  27. S_PARTIAL_CONTENT = 206,
  28. S_MOVED_PERMANENTLY = 301,
  29. S_NOT_MODIFIED = 304,
  30. S_BAD_REQUEST = 400,
  31. S_FORBIDDEN = 403,
  32. S_NOT_FOUND = 404,
  33. S_METHOD_NOT_ALLOWED = 405,
  34. S_REQUEST_TIMEOUT = 408,
  35. S_RANGE_NOT_SATISFIABLE = 416,
  36. S_REQUEST_TOO_LARGE = 431,
  37. S_INTERNAL_SERVER_ERROR = 500,
  38. S_VERSION_NOT_SUPPORTED = 505,
  39. };
  40. extern const char *status_str[];
  41. enum status http_send_status(int, enum status);
  42. int http_get_request(int, struct request *);
  43. enum status http_send_response(int, struct request *);
  44. #endif /* HTTP_H */