2222#include "thirdparty/php_http_parser.h"
2323#include "thirdparty/multipart_parser.h"
2424
25+ #ifdef SW_USE_HTTP2
26+ #include <nghttp2/nghttp2.h>
27+ #endif
28+
29+ enum http_callback_type
30+ {
31+ HTTP_CALLBACK_onRequest = 0 ,
32+ HTTP_CALLBACK_onHandShake = 1 ,
33+ };
34+
35+ enum http_response_flag
36+ {
37+ HTTP_RESPONSE_SERVER = 1u << 1 ,
38+ HTTP_RESPONSE_CONNECTION = 1u << 2 ,
39+ HTTP_RESPONSE_CONTENT_LENGTH = 1u << 3 ,
40+ HTTP_RESPONSE_DATE = 1u << 4 ,
41+ HTTP_RESPONSE_CONTENT_TYPE = 1u << 5 ,
42+ };
43+
2544typedef struct
2645{
2746 enum php_http_method method ;
@@ -65,25 +84,22 @@ typedef struct
6584
6685 uint32_t end :1 ;
6786 uint32_t send_header :1 ;
68- uint32_t chunk :1 ;
69- uint32_t keepalive :1 ;
70-
7187 uint32_t gzip_enable :1 ;
7288 uint32_t gzip_level :4 ;
73-
74- uint32_t request_read :1 ;
75- uint32_t current_header_name_allocated :1 ;
76- uint32_t content_sender_initialized :1 ;
77-
89+ uint32_t chunk :1 ;
90+ uint32_t keepalive :1 ;
7891 uint32_t http2 :1 ;
7992
93+ uint8_t priority ;
94+ uint32_t stream_id ;
95+
8096 http_request request ;
8197 http_response response ;
8298
8399#if PHP_MAJOR_VERSION >= 7
84100 struct
85101 {
86- zval zrequest_object ;
102+ zval zobject ;
87103 zval zrequest ;
88104 zval zserver ;
89105 zval zheader ;
@@ -95,12 +111,31 @@ typedef struct
95111 } request_stack ;
96112 struct
97113 {
98- zval zresponse_object ;
114+ zval zobject ;
99115 zval zheader ;
100116 zval zcookie ;
101117 } response_stack ;
102118#endif
103119
120+ } http_context ;
121+
122+ typedef struct _swoole_http_client
123+ {
124+ int fd ;
125+
126+ uint32_t request_read :1 ;
127+ uint32_t current_header_name_allocated :1 ;
128+ uint32_t content_sender_initialized :1 ;
129+ uint32_t http2 :1 ;
130+
131+ #ifdef SW_USE_HTTP2
132+ swHashMap * streams ;
133+ nghttp2_hd_inflater * deflater ;
134+ nghttp2_hd_inflater * inflater ;
135+ #endif
136+
137+ http_context context ;
138+
104139 php_http_parser parser ;
105140 multipart_parser * mt_parser ;
106141
@@ -114,12 +149,24 @@ typedef struct
114149
115150} swoole_http_client ;
116151
152+ /**
153+ * WebSocket
154+ */
117155int swoole_websocket_onMessage (swEventData * req );
118156int swoole_websocket_onHandshake (swoole_http_client * client );
119157void swoole_websocket_onOpen (swoole_http_client * client );
120158void swoole_websocket_onReuqest (swoole_http_client * client );
121159int swoole_websocket_isset_onMessage (void );
122- void swoole_http_request_free (swoole_http_client * client TSRMLS_DC );
160+ /**
161+ * Http Context
162+ */
163+ http_context * swoole_http_context_new (swoole_http_client * client TSRMLS_DC );
164+ void swoole_http_context_free (http_context * ctx TSRMLS_DC );
165+ /**
166+ * Http v2
167+ */
168+ int swoole_http2_onFrame (swoole_http_client * client , swEventData * req );
169+ int swoole_http2_do_response (http_context * ctx , swString * body );
123170
124171extern zend_class_entry swoole_http_server_ce ;
125172extern zend_class_entry * swoole_http_server_class_entry_ptr ;
@@ -133,4 +180,6 @@ extern zend_class_entry *swoole_http_request_class_entry_ptr;
133180extern swString * swoole_http_buffer ;
134181extern swString * swoole_zlib_buffer ;
135182
183+ extern zval * php_sw_http_server_callbacks [2 ];
184+
136185#endif /* SWOOLE_HTTP_H_ */
0 commit comments