@@ -166,7 +166,9 @@ static ngx_js_http_t *ngx_js_http_alloc(njs_vm_t *vm, ngx_pool_t *pool,
166
166
static void ngx_js_http_resolve_done (ngx_js_http_t * http );
167
167
static void ngx_js_http_close_peer (ngx_js_http_t * http );
168
168
static void ngx_js_http_destructor (ngx_js_event_t * event );
169
- static void ngx_js_resolve_handler (ngx_resolver_ctx_t * ctx );
169
+ static ngx_resolver_ctx_t * ngx_js_http_resolve (ngx_js_http_t * http ,
170
+ ngx_resolver_t * r , ngx_str_t * host , in_port_t port , ngx_msec_t timeout );
171
+ static void ngx_js_http_resolve_handler (ngx_resolver_ctx_t * ctx );
170
172
static njs_int_t ngx_js_fetch_promissified_result (njs_vm_t * vm ,
171
173
njs_value_t * result , njs_int_t rc , njs_value_t * retval );
172
174
static void ngx_js_http_fetch_done (ngx_js_http_t * http ,
@@ -832,7 +834,9 @@ ngx_js_ext_fetch(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
832
834
}
833
835
834
836
if (u .addrs == NULL ) {
835
- ctx = ngx_resolve_start (ngx_external_resolver (vm , external ), NULL );
837
+ ctx = ngx_js_http_resolve (http , ngx_external_resolver (vm , external ),
838
+ & u .host , u .port ,
839
+ ngx_external_resolver_timeout (vm , external ));
836
840
if (ctx == NULL ) {
837
841
njs_vm_memory_error (vm );
838
842
return NJS_ERROR ;
@@ -843,21 +847,6 @@ ngx_js_ext_fetch(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
843
847
goto fail ;
844
848
}
845
849
846
- http -> ctx = ctx ;
847
- http -> port = u .port ;
848
-
849
- ctx -> name = u .host ;
850
- ctx -> handler = ngx_js_resolve_handler ;
851
- ctx -> data = http ;
852
- ctx -> timeout = ngx_external_resolver_timeout (vm , external );
853
-
854
- ret = ngx_resolve_name (http -> ctx );
855
- if (ret != NGX_OK ) {
856
- http -> ctx = NULL ;
857
- njs_vm_memory_error (vm );
858
- return NJS_ERROR ;
859
- }
860
-
861
850
njs_value_assign (retval , njs_value_arg (& http -> promise ));
862
851
863
852
return NJS_OK ;
@@ -1341,8 +1330,42 @@ ngx_js_http_error(ngx_js_http_t *http, const char *fmt, ...)
1341
1330
}
1342
1331
1343
1332
1333
+ static ngx_resolver_ctx_t *
1334
+ ngx_js_http_resolve (ngx_js_http_t * http , ngx_resolver_t * r , ngx_str_t * host ,
1335
+ in_port_t port , ngx_msec_t timeout )
1336
+ {
1337
+ ngx_int_t ret ;
1338
+ ngx_resolver_ctx_t * ctx ;
1339
+
1340
+ ctx = ngx_resolve_start (r , NULL );
1341
+ if (ctx == NULL ) {
1342
+ return NULL ;
1343
+ }
1344
+
1345
+ if (ctx == NGX_NO_RESOLVER ) {
1346
+ return ctx ;
1347
+ }
1348
+
1349
+ http -> ctx = ctx ;
1350
+ http -> port = port ;
1351
+
1352
+ ctx -> name = * host ;
1353
+ ctx -> handler = ngx_js_http_resolve_handler ;
1354
+ ctx -> data = http ;
1355
+ ctx -> timeout = timeout ;
1356
+
1357
+ ret = ngx_resolve_name (ctx );
1358
+ if (ret != NGX_OK ) {
1359
+ http -> ctx = NULL ;
1360
+ return NULL ;
1361
+ }
1362
+
1363
+ return ctx ;
1364
+ }
1365
+
1366
+
1344
1367
static void
1345
- ngx_js_resolve_handler (ngx_resolver_ctx_t * ctx )
1368
+ ngx_js_http_resolve_handler (ngx_resolver_ctx_t * ctx )
1346
1369
{
1347
1370
u_char * p ;
1348
1371
size_t len ;
0 commit comments