1 /*
2 http.h
3 Copyright (C) 1999 Lars Brinkhoff.  See COPYING for terms and conditions.
4 */
5 
6 #include <sys/types.h>
7 
8 /* All HTTP methods mankind (i.e. RFC2068) knows. */
9 /* Actually, Netscape has defined some CONNECT method, but */
10 /* I don't know much about it. */
11 typedef enum
12 {
13   HTTP_GET,
14   HTTP_PUT,
15   HTTP_POST,
16   HTTP_OPTIONS,
17   HTTP_HEAD,
18   HTTP_DELETE,
19   HTTP_TRACE
20 } Http_method;
21 
22 typedef struct http_header Http_header;
23 struct http_header
24 {
25   const char *name;
26   const char *value;
27   Http_header *next; /* FIXME: this is ugly; need cons cell. */
28 };
29 
30 typedef struct
31 {
32   Http_method method;
33   const char *uri;
34   int major_version;
35   int minor_version;
36   Http_header *header;
37 } Http_request;
38 
39 typedef struct
40 {
41    int major_version;
42    int minor_version;
43    int status_code;
44    const char *status_message;
45    Http_header *header;
46 } Http_response;
47 
48 typedef struct
49 {
50   const char *host_name;
51   int host_port;
52   const char *proxy_name;
53   int proxy_port;
54   const char *proxy_authorization;
55   const char *user_agent;
56 } Http_destination;
57 
58 extern ssize_t http_get (int fd, Http_destination *dest);
59 extern ssize_t http_put (int fd, Http_destination *dest,
60 			 size_t content_length);
61 extern ssize_t http_post (int fd, Http_destination *dest,
62 			  size_t content_length);
63 extern int http_error_to_errno (int err);
64 
65 extern Http_response *http_create_response (int major_version,
66 					    int minor_version,
67 					    int status_code,
68 					    const char *status_message);
69 extern ssize_t http_parse_response (int fd, Http_response **response);
70 extern void http_destroy_response (Http_response *response);
71 
72 extern Http_header *http_add_header (Http_header **header,
73 				     const char *name,
74 				     const char *value);
75 
76 extern Http_request *http_create_request (Http_method method,
77 					  const char *uri,
78 					  int major_version,
79 					  int minor_version);
80 extern ssize_t http_parse_request (int fd, Http_request **request);
81 extern ssize_t http_write_request (int fd, Http_request *request);
82 extern void http_destroy_request (Http_request *resquest);
83 
84 extern const char *http_header_get (Http_header *header, const char *name);
85