@@ -14,7 +14,7 @@ static ngx_int_t ngx_http_redirectionio_send_string(ngx_connection_t *c, const c
14
14
15
15
static ngx_int_t ngx_http_redirectionio_send_protocol_header (ngx_connection_t * c , ngx_str_t * project_key , uint16_t command );
16
16
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 ) {
18
18
ngx_int_t rv ;
19
19
ngx_table_elt_t * h ;
20
20
ngx_list_part_t * part ;
@@ -101,23 +101,27 @@ void ngx_http_redirectionio_protocol_send_match(ngx_connection_t *c, ngx_http_re
101
101
ctx -> request = (struct REDIRECTIONIO_Request * )redirectionio_request_create (uri , host , scheme , method , first_header );
102
102
103
103
if (ctx -> request == NULL ) {
104
- return ;
104
+ return NGX_ERROR ;
105
105
}
106
106
107
107
// Serialize request
108
108
request_serialized = redirectionio_request_json_serialize (ctx -> request );
109
109
110
110
if (request_serialized == NULL ) {
111
- return ;
111
+ return NGX_ERROR ;
112
112
}
113
113
114
114
// Send protocol header
115
115
rv = ngx_http_redirectionio_send_protocol_header (c , project_key , REDIRECTIONIO_PROTOCOL_COMMAND_MATCH_ACTION );
116
116
117
+ if (rv == NGX_AGAIN ) {
118
+ return rv ;
119
+ }
120
+
117
121
if (rv != NGX_OK ) {
118
122
ctx -> connection_error = 1 ;
119
123
120
- return ;
124
+ return NGX_ERROR ;
121
125
}
122
126
123
127
// Send serialized request length
@@ -126,7 +130,7 @@ void ngx_http_redirectionio_protocol_send_match(ngx_connection_t *c, ngx_http_re
126
130
if (rv != NGX_OK ) {
127
131
ctx -> connection_error = 1 ;
128
132
129
- return ;
133
+ return NGX_ERROR ;
130
134
}
131
135
132
136
// Send serialized request
@@ -135,10 +139,13 @@ void ngx_http_redirectionio_protocol_send_match(ngx_connection_t *c, ngx_http_re
135
139
free ((void * )request_serialized );
136
140
137
141
if (rv != NGX_OK ) {
142
+ ngx_log_error (NGX_LOG_ERR , c -> log , 0 , "[redirectionio] error sending request: %d" , rv );
138
143
ctx -> connection_error = 1 ;
139
144
140
- return ;
145
+ return NGX_ERROR ;
141
146
}
147
+
148
+ return NGX_OK ;
142
149
}
143
150
144
151
ngx_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
148
155
// Send protocol header
149
156
rv = ngx_http_redirectionio_send_protocol_header (c , & log -> project_key , REDIRECTIONIO_PROTOCOL_COMMAND_LOG );
150
157
151
- if (rv != NGX_OK ) {
158
+ if (rv == NGX_AGAIN ) {
152
159
return rv ;
153
160
}
154
161
162
+ if (rv != NGX_OK ) {
163
+ return NGX_ERROR ;
164
+ }
165
+
155
166
// Send log length
156
167
rv = ngx_http_redirectionio_send_uint32 (c , wlen );
157
168
158
169
if (rv != NGX_OK ) {
159
- return rv ;
170
+ return NGX_ERROR ;
160
171
}
161
172
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 ;
163
180
}
164
181
165
182
ngx_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
294
311
// Send protocol major version
295
312
rv = ngx_http_redirectionio_send_uint8 (c , REDIRECTIONIO_PROTOCOL_VERSION_MAJOR );
296
313
314
+ if (rv == NGX_AGAIN ) {
315
+ return rv ;
316
+ }
317
+
297
318
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 );
299
320
300
321
return rv ;
301
322
}
@@ -304,7 +325,7 @@ static ngx_int_t ngx_http_redirectionio_send_protocol_header(ngx_connection_t *c
304
325
rv = ngx_http_redirectionio_send_uint8 (c , REDIRECTIONIO_PROTOCOL_VERSION_MINOR );
305
326
306
327
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 );
308
329
309
330
return rv ;
310
331
}
@@ -313,23 +334,23 @@ static ngx_int_t ngx_http_redirectionio_send_protocol_header(ngx_connection_t *c
313
334
rv = ngx_http_redirectionio_send_uint8 (c , (unsigned char )project_key -> len );
314
335
315
336
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 );
317
338
318
339
return rv ;
319
340
}
320
341
321
342
rv = ngx_http_redirectionio_send_string (c , (const char * )project_key -> data , project_key -> len );
322
343
323
344
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 );
325
346
326
347
return rv ;
327
348
}
328
349
329
350
rv = ngx_http_redirectionio_send_uint16 (c , command );
330
351
331
352
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 );
333
354
334
355
return rv ;
335
356
}
0 commit comments