@@ -14,7 +14,7 @@ static ngx_int_t ngx_http_redirectionio_send_string(ngx_connection_t *c, const c
1414
1515static ngx_int_t ngx_http_redirectionio_send_protocol_header (ngx_connection_t * c , ngx_str_t * project_key , uint16_t command );
1616
17- void ngx_http_redirectionio_protocol_send_match (ngx_connection_t * c , ngx_http_request_t * r , ngx_http_redirectionio_ctx_t * ctx , ngx_str_t * project_key ) {
17+ ngx_int_t ngx_http_redirectionio_protocol_send_match (ngx_connection_t * c , ngx_http_request_t * r , ngx_http_redirectionio_ctx_t * ctx , ngx_str_t * project_key ) {
1818 ngx_int_t rv ;
1919 ngx_table_elt_t * h ;
2020 ngx_list_part_t * part ;
@@ -101,23 +101,27 @@ void ngx_http_redirectionio_protocol_send_match(ngx_connection_t *c, ngx_http_re
101101 ctx -> request = (struct REDIRECTIONIO_Request * )redirectionio_request_create (uri , host , scheme , method , first_header );
102102
103103 if (ctx -> request == NULL ) {
104- return ;
104+ return NGX_ERROR ;
105105 }
106106
107107 // Serialize request
108108 request_serialized = redirectionio_request_json_serialize (ctx -> request );
109109
110110 if (request_serialized == NULL ) {
111- return ;
111+ return NGX_ERROR ;
112112 }
113113
114114 // Send protocol header
115115 rv = ngx_http_redirectionio_send_protocol_header (c , project_key , REDIRECTIONIO_PROTOCOL_COMMAND_MATCH_ACTION );
116116
117+ if (rv == NGX_AGAIN ) {
118+ return rv ;
119+ }
120+
117121 if (rv != NGX_OK ) {
118122 ctx -> connection_error = 1 ;
119123
120- return ;
124+ return NGX_ERROR ;
121125 }
122126
123127 // Send serialized request length
@@ -126,7 +130,7 @@ void ngx_http_redirectionio_protocol_send_match(ngx_connection_t *c, ngx_http_re
126130 if (rv != NGX_OK ) {
127131 ctx -> connection_error = 1 ;
128132
129- return ;
133+ return NGX_ERROR ;
130134 }
131135
132136 // Send serialized request
@@ -135,10 +139,13 @@ void ngx_http_redirectionio_protocol_send_match(ngx_connection_t *c, ngx_http_re
135139 free ((void * )request_serialized );
136140
137141 if (rv != NGX_OK ) {
142+ ngx_log_error (NGX_LOG_ERR , c -> log , 0 , "[redirectionio] error sending request: %d" , rv );
138143 ctx -> connection_error = 1 ;
139144
140- return ;
145+ return NGX_ERROR ;
141146 }
147+
148+ return NGX_OK ;
142149}
143150
144151ngx_int_t ngx_http_redirectionio_protocol_send_log (ngx_connection_t * c , ngx_http_redirectionio_log_t * log ) {
@@ -148,18 +155,28 @@ ngx_int_t ngx_http_redirectionio_protocol_send_log(ngx_connection_t *c, ngx_http
148155 // Send protocol header
149156 rv = ngx_http_redirectionio_send_protocol_header (c , & log -> project_key , REDIRECTIONIO_PROTOCOL_COMMAND_LOG );
150157
151- if (rv != NGX_OK ) {
158+ if (rv == NGX_AGAIN ) {
152159 return rv ;
153160 }
154161
162+ if (rv != NGX_OK ) {
163+ return NGX_ERROR ;
164+ }
165+
155166 // Send log length
156167 rv = ngx_http_redirectionio_send_uint32 (c , wlen );
157168
158169 if (rv != NGX_OK ) {
159- return rv ;
170+ return NGX_ERROR ;
160171 }
161172
162- return ngx_http_redirectionio_send_string (c , log -> log_serialized , wlen );
173+ rv = ngx_http_redirectionio_send_string (c , log -> log_serialized , wlen );
174+
175+ if (rv != NGX_OK ) {
176+ return NGX_ERROR ;
177+ }
178+
179+ return NGX_OK ;
163180}
164181
165182ngx_http_redirectionio_log_t * ngx_http_redirectionio_protocol_create_log (ngx_http_request_t * r , ngx_http_redirectionio_ctx_t * ctx , ngx_str_t * project_key ) {
@@ -294,8 +311,12 @@ static ngx_int_t ngx_http_redirectionio_send_protocol_header(ngx_connection_t *c
294311 // Send protocol major version
295312 rv = ngx_http_redirectionio_send_uint8 (c , REDIRECTIONIO_PROTOCOL_VERSION_MAJOR );
296313
314+ if (rv == NGX_AGAIN ) {
315+ return rv ;
316+ }
317+
297318 if (rv != NGX_OK ) {
298- ngx_log_error (NGX_LOG_ERR , c -> log , 0 , "[redirectionio] error sending protocol major version" );
319+ ngx_log_error (NGX_LOG_ERR , c -> log , 0 , "[redirectionio] error sending protocol major version: %d" , rv );
299320
300321 return rv ;
301322 }
@@ -304,7 +325,7 @@ static ngx_int_t ngx_http_redirectionio_send_protocol_header(ngx_connection_t *c
304325 rv = ngx_http_redirectionio_send_uint8 (c , REDIRECTIONIO_PROTOCOL_VERSION_MINOR );
305326
306327 if (rv != NGX_OK ) {
307- ngx_log_error (NGX_LOG_ERR , c -> log , 0 , "[redirectionio] error sending protocol minor version" );
328+ ngx_log_error (NGX_LOG_ERR , c -> log , 0 , "[redirectionio] error sending protocol minor version: %d" , rv );
308329
309330 return rv ;
310331 }
@@ -313,23 +334,23 @@ static ngx_int_t ngx_http_redirectionio_send_protocol_header(ngx_connection_t *c
313334 rv = ngx_http_redirectionio_send_uint8 (c , (unsigned char )project_key -> len );
314335
315336 if (rv != NGX_OK ) {
316- ngx_log_error (NGX_LOG_ERR , c -> log , 0 , "[redirectionio] error sending project key length" );
337+ ngx_log_error (NGX_LOG_ERR , c -> log , 0 , "[redirectionio] error sending project key length: %d" , rv );
317338
318339 return rv ;
319340 }
320341
321342 rv = ngx_http_redirectionio_send_string (c , (const char * )project_key -> data , project_key -> len );
322343
323344 if (rv != NGX_OK ) {
324- ngx_log_error (NGX_LOG_ERR , c -> log , 0 , "[redirectionio] error sending project key" );
345+ ngx_log_error (NGX_LOG_ERR , c -> log , 0 , "[redirectionio] error sending project key: %d" , rv );
325346
326347 return rv ;
327348 }
328349
329350 rv = ngx_http_redirectionio_send_uint16 (c , command );
330351
331352 if (rv != NGX_OK ) {
332- ngx_log_error (NGX_LOG_ERR , c -> log , 0 , "[redirectionio] error sending command" );
353+ ngx_log_error (NGX_LOG_ERR , c -> log , 0 , "[redirectionio] error sending command: %d" , rv );
333354
334355 return rv ;
335356 }
0 commit comments