Skip to content

Commit b5d69df

Browse files
committed
Fetch: expose ngx_js_http_trim() and njs_is_token().
1 parent bc2c4a8 commit b5d69df

File tree

3 files changed

+90
-90
lines changed

3 files changed

+90
-90
lines changed

nginx/ngx_js_fetch.c

-90
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@ static njs_int_t ngx_response_js_ext_type(njs_vm_t *vm,
116116
static njs_int_t ngx_response_js_ext_body(njs_vm_t *vm, njs_value_t *args,
117117
njs_uint_t nargs, njs_index_t unused, njs_value_t *retval);
118118

119-
static void ngx_js_http_trim(u_char **value, size_t *len,
120-
njs_bool_t trim_c0_control_or_space);
121119
static njs_int_t ngx_fetch_flag(njs_vm_t *vm, const ngx_js_entry_t *entries,
122120
njs_int_t value, njs_value_t *retval);
123121
static njs_int_t ngx_fetch_flag_set(njs_vm_t *vm, const ngx_js_entry_t *entries,
@@ -1532,94 +1530,6 @@ ngx_js_request_constructor(njs_vm_t *vm, ngx_js_request_t *request,
15321530
}
15331531

15341532

1535-
njs_inline njs_int_t
1536-
ngx_js_http_whitespace(u_char c)
1537-
{
1538-
switch (c) {
1539-
case 0x09: /* <TAB> */
1540-
case 0x0A: /* <LF> */
1541-
case 0x0D: /* <CR> */
1542-
case 0x20: /* <SP> */
1543-
return 1;
1544-
1545-
default:
1546-
return 0;
1547-
}
1548-
}
1549-
1550-
1551-
static void
1552-
ngx_js_http_trim(u_char **value, size_t *len,
1553-
njs_bool_t trim_c0_control_or_space)
1554-
{
1555-
u_char *start, *end;
1556-
1557-
start = *value;
1558-
end = start + *len;
1559-
1560-
for ( ;; ) {
1561-
if (start == end) {
1562-
break;
1563-
}
1564-
1565-
if (ngx_js_http_whitespace(*start)
1566-
|| (trim_c0_control_or_space && *start <= ' '))
1567-
{
1568-
start++;
1569-
continue;
1570-
}
1571-
1572-
break;
1573-
}
1574-
1575-
for ( ;; ) {
1576-
if (start == end) {
1577-
break;
1578-
}
1579-
1580-
end--;
1581-
1582-
if (ngx_js_http_whitespace(*end)
1583-
|| (trim_c0_control_or_space && *end <= ' '))
1584-
{
1585-
continue;
1586-
}
1587-
1588-
end++;
1589-
break;
1590-
}
1591-
1592-
*value = start;
1593-
*len = end - start;
1594-
}
1595-
1596-
1597-
static const uint32_t token_map[] = {
1598-
0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
1599-
1600-
/* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */
1601-
0x03ff6cfa, /* 0000 0011 1111 1111 0110 1100 1111 1010 */
1602-
1603-
/* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */
1604-
0xc7fffffe, /* 1100 0111 1111 1111 1111 1111 1111 1110 */
1605-
1606-
/* ~}| {zyx wvut srqp onml kjih gfed cba` */
1607-
0x57ffffff, /* 0101 0111 1111 1111 1111 1111 1111 1111 */
1608-
1609-
0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
1610-
0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
1611-
0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
1612-
0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
1613-
};
1614-
1615-
1616-
njs_inline njs_bool_t
1617-
njs_is_token(uint32_t byte)
1618-
{
1619-
return ((token_map[byte >> 5] & ((uint32_t) 1 << (byte & 0x1f))) != 0);
1620-
}
1621-
1622-
16231533
static ngx_int_t
16241534
ngx_js_fetch_append_headers(ngx_js_http_t *http, ngx_js_headers_t *headers,
16251535
u_char *name, size_t len, u_char *value, size_t vlen)

nginx/ngx_js_http.c

+62
Original file line numberDiff line numberDiff line change
@@ -1422,3 +1422,65 @@ ngx_js_http_parse_chunked(ngx_js_http_chunk_parse_t *hcp,
14221422

14231423
return NGX_AGAIN;
14241424
}
1425+
1426+
1427+
njs_inline njs_int_t
1428+
ngx_js_http_whitespace(u_char c)
1429+
{
1430+
switch (c) {
1431+
case 0x09: /* <TAB> */
1432+
case 0x0A: /* <LF> */
1433+
case 0x0D: /* <CR> */
1434+
case 0x20: /* <SP> */
1435+
return 1;
1436+
1437+
default:
1438+
return 0;
1439+
}
1440+
}
1441+
1442+
1443+
void
1444+
ngx_js_http_trim(u_char **value, size_t *len,
1445+
njs_bool_t trim_c0_control_or_space)
1446+
{
1447+
u_char *start, *end;
1448+
1449+
start = *value;
1450+
end = start + *len;
1451+
1452+
for ( ;; ) {
1453+
if (start == end) {
1454+
break;
1455+
}
1456+
1457+
if (ngx_js_http_whitespace(*start)
1458+
|| (trim_c0_control_or_space && *start <= ' '))
1459+
{
1460+
start++;
1461+
continue;
1462+
}
1463+
1464+
break;
1465+
}
1466+
1467+
for ( ;; ) {
1468+
if (start == end) {
1469+
break;
1470+
}
1471+
1472+
end--;
1473+
1474+
if (ngx_js_http_whitespace(*end)
1475+
|| (trim_c0_control_or_space && *end <= ' '))
1476+
{
1477+
continue;
1478+
}
1479+
1480+
end++;
1481+
break;
1482+
}
1483+
1484+
*value = start;
1485+
*len = end - start;
1486+
}

nginx/ngx_js_http.h

+28
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,34 @@ ngx_resolver_ctx_t *ngx_js_http_resolve(ngx_js_http_t *http, ngx_resolver_t *r,
152152
void ngx_js_http_connect(ngx_js_http_t *http);
153153
void ngx_js_http_resolve_done(ngx_js_http_t *http);
154154
void ngx_js_http_close_peer(ngx_js_http_t *http);
155+
void ngx_js_http_trim(u_char **value, size_t *len,
156+
njs_bool_t trim_c0_control_or_space);
157+
158+
159+
static const uint32_t token_map[] = {
160+
0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
161+
162+
/* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */
163+
0x03ff6cfa, /* 0000 0011 1111 1111 0110 1100 1111 1010 */
164+
165+
/* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */
166+
0xc7fffffe, /* 1100 0111 1111 1111 1111 1111 1111 1110 */
167+
168+
/* ~}| {zyx wvut srqp onml kjih gfed cba` */
169+
0x57ffffff, /* 0101 0111 1111 1111 1111 1111 1111 1111 */
170+
171+
0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
172+
0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
173+
0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
174+
0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
175+
};
176+
177+
178+
njs_inline njs_bool_t
179+
njs_is_token(uint32_t byte)
180+
{
181+
return ((token_map[byte >> 5] & ((uint32_t) 1 << (byte & 0x1f))) != 0);
182+
}
155183

156184

157185
#endif /* _NGX_JS_HTTP_H_INCLUDED_ */

0 commit comments

Comments
 (0)