[multiple] use light_btst() for hdr existence chk

This commit is contained in:
Glenn Strauss 2020-10-09 02:58:41 -04:00
parent bd8edb51d0
commit 4d6d1e790a
6 changed files with 15 additions and 23 deletions

View File

@ -186,10 +186,9 @@ int http_response_handle_cachable(request_st * const r, const buffer * const mti
CONST_STR_LEN("If-None-Match")))) {
/*(weak etag comparison must not be used for ranged requests)*/
int range_request =
(r->conf.range_requests
&& (200 == r->http_status || 0 == r->http_status)
&& NULL != http_header_request_get(r, HTTP_HEADER_RANGE,
CONST_STR_LEN("Range")));
(light_btst(r->rqst_htags, HTTP_HEADER_RANGE)
&& r->conf.range_requests
&& (200 == r->http_status || 0 == r->http_status));
if (etag_is_equal(&r->physical.etag, vb->ptr, !range_request)) {
if (http_method_get_or_head(r->http_method)) {
r->http_status = 304;
@ -582,8 +581,7 @@ void http_response_send_file (request_st * const r, buffer * const path) {
/* set response content-type, if not set already */
if (NULL == http_header_response_get(r, HTTP_HEADER_CONTENT_TYPE,
CONST_STR_LEN("Content-Type"))) {
if (!light_btst(r->resp_htags, HTTP_HEADER_CONTENT_TYPE)) {
const buffer *content_type = stat_cache_content_type_get(sce, r);
if (buffer_string_is_empty(content_type)) {
/* we are setting application/octet-stream, but also announce that
@ -611,15 +609,13 @@ void http_response_send_file (request_st * const r, buffer * const path) {
}
if (allow_caching) {
const buffer *etag = (0 != r->conf.etag_flags)
? stat_cache_etag_get(sce, r->conf.etag_flags)
: NULL;
if (!buffer_string_is_empty(etag)) {
if (NULL == http_header_response_get(r, HTTP_HEADER_ETAG,
CONST_STR_LEN("ETag"))) {
if (!light_btst(r->resp_htags, HTTP_HEADER_ETAG)
&& 0 != r->conf.etag_flags) {
const buffer *etag =
stat_cache_etag_get(sce, r->conf.etag_flags);
if (!buffer_string_is_empty(etag)) {
/* generate e-tag */
etag_mutate(&r->physical.etag, etag);
http_header_response_set(r, HTTP_HEADER_ETAG,
CONST_STR_LEN("ETag"),
CONST_BUF_LEN(&r->physical.etag));
@ -656,8 +652,7 @@ void http_response_send_file (request_st * const r, buffer * const path) {
&& (200 == r->http_status || 0 == r->http_status)
&& NULL != (vb = http_header_request_get(r, HTTP_HEADER_RANGE,
CONST_STR_LEN("Range")))
&& NULL == http_header_response_get(r, HTTP_HEADER_CONTENT_ENCODING,
CONST_STR_LEN("Content-Encoding"))) {
&& !light_btst(r->resp_htags, HTTP_HEADER_CONTENT_ENCODING)) {
const buffer *range = vb;
int do_range_request = 1;
/* check if we have a conditional GET */

View File

@ -906,7 +906,7 @@ URIHANDLER_FUNC(cgi_is_handled) {
hctx->conf.upgrade =
hctx->conf.upgrade
&& r->http_version == HTTP_VERSION_1_1
&& NULL != http_header_request_get(r, HTTP_HEADER_UPGRADE, CONST_STR_LEN("Upgrade"));
&& light_btst(r->rqst_htags, HTTP_HEADER_UPGRADE);
hctx->opts.fdfmt = S_IFIFO;
hctx->opts.backend = BACKEND_CGI;
hctx->opts.authorizer = 0;

View File

@ -1532,8 +1532,7 @@ REQUEST_FUNC(mod_deflate_handle_response_start) {
&& r->write_queue.first->type == FILE_CHUNK
&& r->write_queue.first->file.start == 0
&& !r->write_queue.first->file.is_temp
&& !http_header_response_get(r, HTTP_HEADER_RANGE,
CONST_STR_LEN("Range"))) {
&& !light_btst(r->resp_htags, HTTP_HEADER_RANGE)) {
tb = mod_deflate_cache_file_name(r, p->conf.cache_dir, vb);
/*(checked earlier and skipped if Transfer-Encoding had been set)*/
stat_cache_entry *sce = stat_cache_get_entry(tb);

View File

@ -1020,7 +1020,7 @@ static handler_t mod_extforward_Forwarded (request_st * const r, plugin_data * c
#if 0
if ((p->conf.opts & PROXY_FORWARDED_CREATE_XFF)
&& NULL == http_header_request_get(r, HTTP_HEADER_X_FORWARDED_FOR, CONST_STR_LEN("X-Forwarded-For"))) {
&& !light_btst(r->rqst_htags, HTTP_HEADER_X_FORWARDED_FOR)) {
/* create X-Forwarded-For if not present
* (and at least original connecting IP is a trusted proxy) */
buffer *xff = r->tmp_buf;

View File

@ -4303,8 +4303,7 @@ mod_webdav_put_0 (request_st * const r, const plugin_config * const pconf)
static handler_t
mod_webdav_put_prep (request_st * const r, const plugin_config * const pconf)
{
if (NULL != http_header_request_get(r, HTTP_HEADER_CONTENT_RANGE,
CONST_STR_LEN("Content-Range"))) {
if (light_btst(r->rqst_htags, HTTP_HEADER_CONTENT_RANGE)) {
if (pconf->opts & MOD_WEBDAV_UNSAFE_PARTIAL_PUT_COMPAT)
return HANDLER_GO_ON;
/* [RFC7231] 4.3.4 PUT

View File

@ -197,8 +197,7 @@ static handler_t http_response_physical_path_check(request_st * const r) {
/* file name to be read was too long. return 404 */
case ENOENT:
if (r->http_method == HTTP_METHOD_OPTIONS
&& NULL != http_header_response_get(r, HTTP_HEADER_ALLOW,
CONST_STR_LEN("Allow"))) {
&& light_btst(r->resp_htags, HTTP_HEADER_ALLOW)) {
r->http_status = 200;
return HANDLER_FINISHED;
}