@@ -90,6 +90,8 @@ static void nxt_h1p_peer_connect(nxt_task_t *task, nxt_http_peer_t *peer);
90
90
static void nxt_h1p_peer_connected (nxt_task_t * task , void * obj , void * data );
91
91
static void nxt_h1p_peer_refused (nxt_task_t * task , void * obj , void * data );
92
92
static void nxt_h1p_peer_header_send (nxt_task_t * task , nxt_http_peer_t * peer );
93
+ static nxt_int_t nxt_h1p_peer_request_target (nxt_http_request_t * r ,
94
+ nxt_str_t * target );
93
95
static void nxt_h1p_peer_header_sent (nxt_task_t * task , void * obj , void * data );
94
96
static void nxt_h1p_peer_header_read (nxt_task_t * task , nxt_http_peer_t * peer );
95
97
static ssize_t nxt_h1p_peer_io_read_handler (nxt_task_t * task , nxt_conn_t * c );
@@ -654,6 +656,8 @@ nxt_h1p_header_process(nxt_task_t *task, nxt_h1proto_t *h1p,
654
656
r -> target .start = h1p -> parser .target_start ;
655
657
r -> target .length = h1p -> parser .target_end - h1p -> parser .target_start ;
656
658
659
+ r -> quoted_target = h1p -> parser .quoted_target ;
660
+
657
661
if (h1p -> parser .version .ui64 != 0 ) {
658
662
r -> version .start = h1p -> parser .version .str ;
659
663
r -> version .length = sizeof (h1p -> parser .version .str );
@@ -2263,6 +2267,8 @@ nxt_h1p_peer_header_send(nxt_task_t *task, nxt_http_peer_t *peer)
2263
2267
{
2264
2268
u_char * p ;
2265
2269
size_t size ;
2270
+ nxt_int_t ret ;
2271
+ nxt_str_t target ;
2266
2272
nxt_buf_t * header , * body ;
2267
2273
nxt_conn_t * c ;
2268
2274
nxt_http_field_t * field ;
@@ -2272,7 +2278,12 @@ nxt_h1p_peer_header_send(nxt_task_t *task, nxt_http_peer_t *peer)
2272
2278
2273
2279
r = peer -> request ;
2274
2280
2275
- size = r -> method -> length + sizeof (" " ) + r -> target .length
2281
+ ret = nxt_h1p_peer_request_target (r , & target );
2282
+ if (nxt_slow_path (ret != NXT_OK )) {
2283
+ goto fail ;
2284
+ }
2285
+
2286
+ size = r -> method -> length + sizeof (" " ) + target .length
2276
2287
+ sizeof (" HTTP/1.1\r\n" )
2277
2288
+ sizeof ("Connection: close\r\n" )
2278
2289
+ sizeof ("\r\n" );
@@ -2288,8 +2299,7 @@ nxt_h1p_peer_header_send(nxt_task_t *task, nxt_http_peer_t *peer)
2288
2299
2289
2300
header = nxt_http_buf_mem (task , r , size );
2290
2301
if (nxt_slow_path (header == NULL )) {
2291
- r -> state -> error_handler (task , r , peer );
2292
- return ;
2302
+ goto fail ;
2293
2303
}
2294
2304
2295
2305
p = header -> mem .free ;
@@ -2328,8 +2338,7 @@ nxt_h1p_peer_header_send(nxt_task_t *task, nxt_http_peer_t *peer)
2328
2338
}
2329
2339
2330
2340
if (nxt_slow_path (body == NULL )) {
2331
- r -> state -> error_handler (task , r , peer );
2332
- return ;
2341
+ goto fail ;
2333
2342
}
2334
2343
2335
2344
header -> next = body ;
@@ -2353,6 +2362,61 @@ nxt_h1p_peer_header_send(nxt_task_t *task, nxt_http_peer_t *peer)
2353
2362
}
2354
2363
2355
2364
nxt_conn_write (task -> thread -> engine , c );
2365
+
2366
+ return ;
2367
+
2368
+ fail :
2369
+
2370
+ r -> state -> error_handler (task , r , peer );
2371
+ }
2372
+
2373
+
2374
+ static nxt_int_t
2375
+ nxt_h1p_peer_request_target (nxt_http_request_t * r , nxt_str_t * target )
2376
+ {
2377
+ u_char * p ;
2378
+ size_t size , encode ;
2379
+
2380
+ if (!r -> uri_changed ) {
2381
+ * target = r -> target ;
2382
+ return NXT_OK ;
2383
+ }
2384
+
2385
+ if (!r -> quoted_target && r -> args -> length == 0 ) {
2386
+ * target = * r -> path ;
2387
+ return NXT_OK ;
2388
+ }
2389
+
2390
+ if (r -> quoted_target ) {
2391
+ encode = nxt_encode_complex_uri (NULL , r -> path -> start ,
2392
+ r -> path -> length );
2393
+ } else {
2394
+ encode = 0 ;
2395
+ }
2396
+
2397
+ size = r -> path -> length + encode * 2 + 1 + r -> args -> length ;
2398
+
2399
+ target -> start = nxt_mp_nget (r -> mem_pool , size );
2400
+ if (target -> start == NULL ) {
2401
+ return NXT_ERROR ;
2402
+ }
2403
+
2404
+ if (r -> quoted_target ) {
2405
+ p = (u_char * ) nxt_encode_complex_uri (target -> start , r -> path -> start ,
2406
+ r -> path -> length );
2407
+
2408
+ } else {
2409
+ p = nxt_cpymem (target -> start , r -> path -> start , r -> path -> length );
2410
+ }
2411
+
2412
+ if (r -> args -> length > 0 ) {
2413
+ * p ++ = '?' ;
2414
+ p = nxt_cpymem (p , r -> args -> start , r -> args -> length );
2415
+ }
2416
+
2417
+ target -> length = p - target -> start ;
2418
+
2419
+ return NXT_OK ;
2356
2420
}
2357
2421
2358
2422
0 commit comments