/http.h

http://github.com/nicolasff/webdis · C Header · 75 lines · 49 code · 25 blank · 1 comment · 0 complexity · ab21e2ac0d0ac9ba38fd719e4636cc13 MD5 · raw file

  1. #ifndef HTTP_H
  2. #define HTTP_H
  3. #include <sys/types.h>
  4. #include <event.h>
  5. struct http_client;
  6. struct worker;
  7. struct http_header {
  8. char *key;
  9. size_t key_sz;
  10. char *val;
  11. size_t val_sz;
  12. };
  13. struct http_response {
  14. struct event ev;
  15. short code;
  16. const char *msg;
  17. struct http_header *headers;
  18. int header_count;
  19. const char *body;
  20. size_t body_len;
  21. char *out;
  22. size_t out_sz;
  23. int chunked;
  24. int http_version;
  25. int keep_alive;
  26. int sent;
  27. struct worker *w;
  28. };
  29. /* HTTP response */
  30. struct http_response *
  31. http_response_init(struct worker *w, int code, const char *msg);
  32. void
  33. http_response_set_header(struct http_response *r, const char *k, const char *v);
  34. void
  35. http_response_set_body(struct http_response *r, const char *body, size_t body_len);
  36. void
  37. http_response_write(struct http_response *r, int fd);
  38. void
  39. http_schedule_write(int fd, struct http_response *r);
  40. void
  41. http_crossdomain(struct http_client *c);
  42. void
  43. http_send_error(struct http_client *c, short code, const char *msg);
  44. void
  45. http_send_options(struct http_client *c);
  46. void
  47. http_response_write_chunk(int fd, struct worker *w, const char *p, size_t sz);
  48. void
  49. http_response_set_keep_alive(struct http_response *r, int enabled);
  50. #endif