fix problem when finishing a chunked encoding stream
[m6w6/ext-http] / php_http_env.h
1 /*
2 +--------------------------------------------------------------------+
3 | PECL :: http |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
11 */
12
13 /* $Id$ */
14
15 #ifndef PHP_HTTP_ENV_H
16 #define PHP_HTTP_ENV_H
17
18 #include "php_http_message_body.h"
19 #include "php_http_encoding.h"
20 #include "php_http_version.h"
21
22 struct php_http_env_globals {
23 zval *server_var;
24 char *etag_mode;
25
26 struct {
27 char *content_type;
28 php_http_message_body_t *body;
29 char *etag;
30 time_t last_modified;
31 double throttle_delay;
32 size_t throttle_chunk;
33 php_http_encoding_stream_t *deflate;
34 } response;
35
36 struct {
37 time_t time;
38 HashTable *headers;
39 php_http_message_body_t *body;
40 } request;
41 };
42
43 typedef enum php_http_range_status {
44 PHP_HTTP_RANGE_NO,
45 PHP_HTTP_RANGE_OK,
46 PHP_HTTP_RANGE_ERR
47 } php_http_range_status_t;
48
49 PHP_HTTP_API php_http_range_status_t php_http_env_get_request_ranges(HashTable *ranges, size_t entity_length TSRMLS_DC);
50 PHP_HTTP_API void php_http_env_get_request_headers(HashTable *headers TSRMLS_DC);
51 PHP_HTTP_API char *php_http_env_get_request_header(const char *name_str, size_t name_len TSRMLS_DC);
52 PHP_HTTP_API int php_http_env_got_request_header(const char *name_str, size_t name_len TSRMLS_DC);
53 PHP_HTTP_API php_http_message_body_t *php_http_env_get_request_body(TSRMLS_D);
54
55 typedef enum php_http_content_disposition {
56 PHP_HTTP_CONTENT_DISPOSITION_NONE,
57 PHP_HTTP_CONTENT_DISPOSITION_INLINE,
58 PHP_HTTP_CONTENT_DISPOSITION_ATTACHMENT
59 } php_http_content_disposition_t;
60
61 typedef enum php_http_cache_status {
62 PHP_HTTP_CACHE_NO,
63 PHP_HTTP_CACHE_HIT,
64 PHP_HTTP_CACHE_MISS
65 } php_http_cache_status_t;
66
67 PHP_HTTP_API long php_http_env_get_response_code(TSRMLS_D);
68 PHP_HTTP_API const char *php_http_env_get_response_status_for_code(unsigned code);
69 PHP_HTTP_API STATUS php_http_env_get_response_headers(HashTable *headers_ht TSRMLS_DC);
70 PHP_HTTP_API char *php_http_env_get_response_header(const char *name_str, size_t name_len TSRMLS_DC);
71 PHP_HTTP_API STATUS php_http_env_set_response_code(long http_code TSRMLS_DC);
72 PHP_HTTP_API STATUS php_http_env_set_response_protocol_version(php_http_version_t *v TSRMLS_DC);
73 PHP_HTTP_API STATUS php_http_env_set_response_header(long http_code, const char *header_str, size_t header_len, zend_bool replace TSRMLS_DC);
74 PHP_HTTP_API STATUS php_http_env_set_response_header_value(long http_code, const char *name_str, size_t name_len, zval *value, zend_bool replace TSRMLS_DC);
75
76 PHP_HTTP_API zval *php_http_env_get_server_var(const char *key_str, size_t key_len, zend_bool check TSRMLS_DC);
77 #define php_http_env_got_server_var(v) (NULL != php_http_env_get_server_var((v), strlen(v), 1 TSRMLS_CC))
78
79 PHP_HTTP_API STATUS php_http_env_set_response_last_modified(zval *container, time_t lm, char **sent_header TSRMLS_DC);
80 PHP_HTTP_API STATUS php_http_env_set_response_etag(zval *container, const char *etag_str, size_t etag_len, char **sent_header TSRMLS_DC);
81 PHP_HTTP_API STATUS php_http_env_set_response_content_type(zval *container, const char *ct_str, size_t ct_len, char **sent_header TSRMLS_DC);
82 PHP_HTTP_API STATUS php_http_env_set_response_content_disposition(zval *container, php_http_content_disposition_t d, const char *f_str, size_t f_len, char **sent_header TSRMLS_DC);
83 PHP_HTTP_API STATUS php_http_env_set_response_cache_control(zval *container, const char *cc_str, size_t cc_len, char **sent_header TSRMLS_DC);
84 PHP_HTTP_API void php_http_env_set_response_throttle_rate(zval *container, size_t chunk_size, double delay TSRMLS_CC);
85 PHP_HTTP_API void php_http_env_set_response_body(zval *container, php_http_message_body_t *body);
86 PHP_HTTP_API STATUS php_http_env_send_response(zval *container TSRMLS_DC);
87 PHP_HTTP_API php_http_cache_status_t php_http_env_is_response_cached_by_etag(zval *container, const char *header_str, size_t header_len TSRMLS_DC);
88 PHP_HTTP_API php_http_cache_status_t php_http_env_is_response_cached_by_last_modified(zval *container, const char *header_str, size_t header_len TSRMLS_DC);
89
90 extern zend_class_entry *php_http_env_class_entry;
91 extern zend_function_entry php_http_env_method_entry[];
92
93 PHP_METHOD(HttpEnv, getRequestHeader);
94 PHP_METHOD(HttpEnv, getRequestBody);
95 PHP_METHOD(HttpEnv, getResponseStatusForCode);
96 PHP_METHOD(HttpEnv, getResponseHeader);
97 PHP_METHOD(HttpEnv, getResponseCode);
98 PHP_METHOD(HttpEnv, setResponseHeader);
99 PHP_METHOD(HttpEnv, setResponseCode);
100 PHP_METHOD(HttpEnv, negotiateLanguage);
101 PHP_METHOD(HttpEnv, negotiateCharset);
102 PHP_METHOD(HttpEnv, negotiateContentType);
103 PHP_METHOD(HttpEnv, negotiate);
104 PHP_METHOD(HttpEnv, persistentHandlesStat);
105 PHP_METHOD(HttpEnv, persistentHandlesClean);
106 PHP_METHOD(HttpEnv, persistentHandlesIdent);
107
108 extern zend_class_entry *php_http_env_request_class_entry;
109 extern zend_function_entry php_http_env_request_method_entry[];
110
111 PHP_METHOD(HttpEnvRequest, __construct);
112
113 extern zend_class_entry *php_http_env_response_class_entry;
114 extern zend_function_entry php_http_env_response_method_entry[];
115
116 PHP_METHOD(HttpEnvResponse, __construct);
117 PHP_METHOD(HttpEnvResponse, setContentType);
118 PHP_METHOD(HttpEnvResponse, setContentDisposition);
119 PHP_METHOD(HttpEnvResponse, setCacheControl);
120 PHP_METHOD(HttpEnvResponse, setLastModified);
121 PHP_METHOD(HttpEnvResponse, isCachedByLastModified);
122 PHP_METHOD(HttpEnvResponse, setEtag);
123 PHP_METHOD(HttpEnvResponse, isCachedByEtag);
124 PHP_METHOD(HttpEnvResponse, setThrottleRate);
125 PHP_METHOD(HttpEnvResponse, send);
126
127 PHP_MINIT_FUNCTION(http_env);
128 PHP_RINIT_FUNCTION(http_env);
129 PHP_RSHUTDOWN_FUNCTION(http_env);
130
131 #endif
132
133 /*
134 * Local variables:
135 * tab-width: 4
136 * c-basic-offset: 4
137 * End:
138 * vim600: noet sw=4 ts=4 fdm=marker
139 * vim<600: noet sw=4 ts=4
140 */
141