@@ -40,7 +40,7 @@ static bool swoole_http2_server_respond(http_context *ctx, String *body);
40
40
41
41
Http2Stream::Stream (Http2Session *client, uint32_t _id) {
42
42
ctx = swoole_http_context_new (client->fd );
43
- swoole_http_context_copy (client->default_ctx , ctx );
43
+ ctx-> copy (client->default_ctx );
44
44
ctx->http2 = true ;
45
45
ctx->stream = this ;
46
46
ctx->keepalive = true ;
@@ -51,8 +51,8 @@ Http2Stream::Stream(Http2Session *client, uint32_t _id) {
51
51
52
52
Http2Stream::~Stream () {
53
53
ctx->stream = nullptr ;
54
- ctx->end = true ;
55
- swoole_http_context_free ( ctx);
54
+ ctx->end_ = true ;
55
+ ctx-> free ( );
56
56
}
57
57
58
58
void Http2Stream::reset (uint32_t error_code) {
@@ -87,7 +87,7 @@ Http2Session::~Session() {
87
87
nghttp2_hd_deflate_del (deflater);
88
88
}
89
89
if (default_ctx) {
90
- efree ( default_ctx) ;
90
+ delete default_ctx;
91
91
}
92
92
http2_sessions.erase (fd);
93
93
}
@@ -172,7 +172,7 @@ static bool swoole_http2_is_static_file(Server *serv, http_context *ctx) {
172
172
auto date_str_last_modified = handler.get_date_last_modified ();
173
173
174
174
zval *zheader = ctx->request .zserver ;
175
- swoole_http_response_set_header ( ctx, ZEND_STRL (" Last-Modified" ), date_str.c_str (), date_str.length (), 0 );
175
+ ctx-> set_header ( ZEND_STRL (" Last-Modified" ), date_str.c_str (), date_str.length (), 0 );
176
176
177
177
zval *zdate_if_modified_since = zend_hash_str_find (Z_ARR_P (zheader), ZEND_STRL (" if-modified-since" ));
178
178
if (zdate_if_modified_since) {
@@ -244,7 +244,7 @@ static ssize_t http2_build_header(http_context *ctx, uchar *buffer, size_t body_
244
244
char intbuf[2 ][16 ];
245
245
int ret;
246
246
247
- assert (ctx->send_header == 0 );
247
+ assert (ctx->send_header_ == 0 );
248
248
249
249
// status code
250
250
if (ctx->response .status == 0 ) {
@@ -314,7 +314,7 @@ static ssize_t http2_build_header(http_context *ctx, uchar *buffer, size_t body_
314
314
// content encoding
315
315
#ifdef SW_HAVE_COMPRESSION
316
316
if (ctx->accept_compression ) {
317
- const char *content_encoding = swoole_http_get_content_encoding ( ctx);
317
+ const char *content_encoding = ctx-> get_content_encoding ( );
318
318
headers.add (ZEND_STRL (" content-encoding" ), (char *) content_encoding, strlen (content_encoding));
319
319
}
320
320
#endif
@@ -353,7 +353,7 @@ static ssize_t http2_build_header(http_context *ctx, uchar *buffer, size_t body_
353
353
return -1 ;
354
354
}
355
355
356
- ctx->send_header = 1 ;
356
+ ctx->send_header_ = 1 ;
357
357
return rv;
358
358
}
359
359
@@ -416,7 +416,7 @@ bool Http2Stream::send_header(size_t body_length, bool end_stream) {
416
416
swoole_http_buffer->append (header_buffer, bytes);
417
417
418
418
if (!ctx->send (ctx, swoole_http_buffer->str , swoole_http_buffer->length )) {
419
- ctx->send_header = 0 ;
419
+ ctx->send_header_ = 0 ;
420
420
return false ;
421
421
}
422
422
@@ -503,7 +503,7 @@ static bool swoole_http2_server_respond(http_context *ctx, String *body) {
503
503
}
504
504
505
505
// The headers has already been sent, retries are no longer allowed (even if send body failed)
506
- ctx->end = 1 ;
506
+ ctx->end_ = 1 ;
507
507
508
508
bool error = false ;
509
509
@@ -602,15 +602,15 @@ static bool http2_context_sendfile(http_context *ctx, const char *file, uint32_t
602
602
}
603
603
604
604
const char *mimetype = swoole::mime_type::get (file).c_str ();
605
- swoole_http_response_set_header ( ctx, ZEND_STRL (" content-type" ), mimetype, strlen (mimetype), 0 );
605
+ ctx-> set_header ( ZEND_STRL (" content-type" ), mimetype, strlen (mimetype), 0 );
606
606
607
607
bool end_stream = (ztrailer == nullptr );
608
608
if (!stream->send_header (length, end_stream)) {
609
609
return false ;
610
610
}
611
611
612
612
/* headers has already been sent, retries are no longer allowed (even if send body failed) */
613
- ctx->end = 1 ;
613
+ ctx->end_ = 1 ;
614
614
615
615
bool error = false ;
616
616
@@ -725,7 +725,7 @@ static int http2_parse_header(Http2Session *client, http_context *ctx, int flags
725
725
swWarn (" invalid multipart/form-data body fd:%ld" , ctx->fd );
726
726
return SW_ERR;
727
727
}
728
- swoole_http_parse_form_data ( ctx, (char *) nv.value + nv.valuelen - boundary_len, boundary_len);
728
+ ctx-> parse_form_data ( (char *) nv.value + nv.valuelen - boundary_len, boundary_len);
729
729
ctx->parser .data = ctx;
730
730
}
731
731
} else if (SW_STRCASEEQ ((char *) nv.name , nv.namelen , " cookie" )) {
@@ -738,7 +738,7 @@ static int http2_parse_header(Http2Session *client, http_context *ctx, int flags
738
738
}
739
739
#ifdef SW_HAVE_COMPRESSION
740
740
else if (ctx->enable_compression && SW_STRCASEEQ ((char *) nv.name , nv.namelen , " accept-encoding" )) {
741
- swoole_http_get_compression_method ( ctx, (char *) nv.value , nv.valuelen );
741
+ ctx-> set_compression_method ( (char *) nv.value , nv.valuelen );
742
742
}
743
743
#endif
744
744
add_assoc_stringl_ex (zheader, (char *) nv.name , nv.namelen , (char *) nv.value , nv.valuelen );
@@ -996,8 +996,8 @@ int swoole_http2_server_onFrame(Server *serv, Connection *conn, RecvData *req) {
996
996
997
997
client->handle = swoole_http2_onRequest;
998
998
if (!client->default_ctx ) {
999
- client->default_ctx = (http_context *) ecalloc ( 1 , sizeof ( http_context) );
1000
- swoole_http_server_init_context (serv, client->default_ctx );
999
+ client->default_ctx = new http_context ( );
1000
+ client->default_ctx -> init (serv );
1001
1001
client->default_ctx ->fd = session_id;
1002
1002
client->default_ctx ->http2 = true ;
1003
1003
client->default_ctx ->stream = (Http2Stream *) -1 ;
@@ -1022,16 +1022,16 @@ void swoole_http2_server_session_free(Connection *conn) {
1022
1022
delete client;
1023
1023
}
1024
1024
1025
- void swoole_http2_response_end ( http_context *ctx, zval *zdata, zval *return_value) {
1026
- swString http_body = {};
1025
+ void http_context::http2_end ( zval *zdata, zval *return_value) {
1026
+ String http_body = {};
1027
1027
if (zdata) {
1028
1028
http_body.length = php_swoole_get_send_data (zdata, &http_body.str );
1029
1029
} else {
1030
1030
http_body.length = 0 ;
1031
1031
http_body.str = nullptr ;
1032
1032
}
1033
1033
1034
- RETURN_BOOL (swoole_http2_server_respond (ctx , &http_body));
1034
+ RETURN_BOOL (swoole_http2_server_respond (this , &http_body));
1035
1035
}
1036
1036
1037
1037
#endif
0 commit comments