httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From grega...@apache.org
Subject cvs commit: httpd-2.0/server core.c
Date Tue, 30 Apr 2002 20:12:27 GMT
gregames    02/04/30 13:12:27

  Modified:    server   core.c
  Log:
  default_handler: move the code to handle unusual methods out of the middle
  of the hot path without using goto.
  
  suggested by: Roy Fielding
  
  Revision  Changes    Path
  1.173     +68 -68    httpd-2.0/server/core.c
  
  Index: core.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/server/core.c,v
  retrieving revision 1.172
  retrieving revision 1.173
  diff -u -r1.172 -r1.173
  --- core.c	25 Apr 2002 20:51:49 -0000	1.172
  +++ core.c	30 Apr 2002 20:12:26 -0000	1.173
  @@ -3167,87 +3167,87 @@
           return errstatus;
       }
   
  -    if (r->method_number != M_GET && r->method_number != M_POST) {
  -        if (r->method_number == M_INVALID) {
  -            ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
  -                          "Invalid method in request %s", r->the_request);
  -            return HTTP_NOT_IMPLEMENTED;
  +    if (r->method_number == M_GET || r->method_number == M_POST) {
  +        if (r->finfo.filetype == 0) {
  +            ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r,
  +                          "File does not exist: %s", r->filename);
  +            return HTTP_NOT_FOUND;
           }
   
  -        if (r->method_number == M_OPTIONS) {
  -            return ap_send_http_options(r);
  +        if ((r->used_path_info != AP_REQ_ACCEPT_PATH_INFO) &&
  +            r->path_info && *r->path_info)
  +        {
  +            /* default to reject */
  +            ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r,
  +                          "File does not exist: %s",
  +                          apr_pstrcat(r->pool, r->filename, r->path_info, NULL));
  +            return HTTP_NOT_FOUND;
           }
  -        return HTTP_METHOD_NOT_ALLOWED;
  -    }
   
  -    if (r->finfo.filetype == 0) {
  -        ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r,
  -                      "File does not exist: %s", r->filename);
  -        return HTTP_NOT_FOUND;
  -    }
  -
  -    if ((r->used_path_info != AP_REQ_ACCEPT_PATH_INFO) &&
  -        r->path_info && *r->path_info)
  -    {
  -        /* default to reject */
  -        ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r,
  -                      "File does not exist: %s",
  -                      apr_pstrcat(r->pool, r->filename, r->path_info, NULL));
  -        return HTTP_NOT_FOUND;
  -    }
  -
  -    if ((status = apr_file_open(&fd, r->filename, APR_READ | APR_BINARY, 0,
  -                                r->pool)) != APR_SUCCESS) {
  -        ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r,
  -                      "file permissions deny server access: %s", r->filename);
  -        return HTTP_FORBIDDEN;
  -    }
  +        if ((status = apr_file_open(&fd, r->filename, APR_READ | APR_BINARY, 0,
  +                                    r->pool)) != APR_SUCCESS) {
  +            ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r,
  +                          "file permissions deny server access: %s", r->filename);
  +            return HTTP_FORBIDDEN;
  +        }
   
  -    ap_update_mtime(r, r->finfo.mtime);
  -    ap_set_last_modified(r);
  -    ap_set_etag(r);
  -    apr_table_setn(r->headers_out, "Accept-Ranges", "bytes");
  -    ap_set_content_length(r, r->finfo.size);
  -    if ((errstatus = ap_meets_conditions(r)) != OK) {
  -        apr_file_close(fd);
  -        return errstatus;
  -    }
  +        ap_update_mtime(r, r->finfo.mtime);
  +        ap_set_last_modified(r);
  +        ap_set_etag(r);
  +        apr_table_setn(r->headers_out, "Accept-Ranges", "bytes");
  +        ap_set_content_length(r, r->finfo.size);
  +        if ((errstatus = ap_meets_conditions(r)) != OK) {
  +            apr_file_close(fd);
  +            return errstatus;
  +        }
   
  -    if (bld_content_md5) {
  -        apr_table_setn(r->headers_out, "Content-MD5",
  -                       ap_md5digest(r->pool, fd));
  -    }
  +        if (bld_content_md5) {
  +            apr_table_setn(r->headers_out, "Content-MD5",
  +                           ap_md5digest(r->pool, fd));
  +        }
   
  -    bb = apr_brigade_create(r->pool, c->bucket_alloc);
  +        bb = apr_brigade_create(r->pool, c->bucket_alloc);
   #if APR_HAS_LARGE_FILES
  -    if (r->finfo.size > AP_MAX_SENDFILE) {
  -        /* APR_HAS_LARGE_FILES issue; must split into mutiple buckets,
  -         * no greater than MAX(apr_size_t), and more granular than that
  -         * in case the brigade code/filters attempt to read it directly.
  -         */
  -        apr_off_t fsize = r->finfo.size;
  -        e = apr_bucket_file_create(fd, 0, AP_MAX_SENDFILE, r->pool,
  -                                   c->bucket_alloc);
  -        while (fsize > AP_MAX_SENDFILE) {
  -            apr_bucket *ce;
  -            apr_bucket_copy(e, &ce);
  -            APR_BRIGADE_INSERT_TAIL(bb, ce);
  -            e->start += AP_MAX_SENDFILE;
  -            fsize -= AP_MAX_SENDFILE;
  +        if (r->finfo.size > AP_MAX_SENDFILE) {
  +            /* APR_HAS_LARGE_FILES issue; must split into mutiple buckets,
  +             * no greater than MAX(apr_size_t), and more granular than that
  +             * in case the brigade code/filters attempt to read it directly.
  +             */
  +            apr_off_t fsize = r->finfo.size;
  +            e = apr_bucket_file_create(fd, 0, AP_MAX_SENDFILE, r->pool,
  +                                       c->bucket_alloc);
  +            while (fsize > AP_MAX_SENDFILE) {
  +                apr_bucket *ce;
  +                apr_bucket_copy(e, &ce);
  +                APR_BRIGADE_INSERT_TAIL(bb, ce);
  +                e->start += AP_MAX_SENDFILE;
  +                fsize -= AP_MAX_SENDFILE;
  +            }
  +            e->length = (apr_size_t)fsize; /* Resize just the last bucket */
           }
  -        e->length = (apr_size_t)fsize; /* Resize just the last bucket */
  -    }
  -    else
  +        else
   #endif
  -        e = apr_bucket_file_create(fd, 0, (apr_size_t)r->finfo.size,
  -                                   r->pool, c->bucket_alloc);
  +            e = apr_bucket_file_create(fd, 0, (apr_size_t)r->finfo.size,
  +                                       r->pool, c->bucket_alloc);
   
  -    APR_BRIGADE_INSERT_TAIL(bb, e);
  -    e = apr_bucket_eos_create(c->bucket_alloc);
  -    APR_BRIGADE_INSERT_TAIL(bb, e);
  +        APR_BRIGADE_INSERT_TAIL(bb, e);
  +        e = apr_bucket_eos_create(c->bucket_alloc);
  +        APR_BRIGADE_INSERT_TAIL(bb, e);
   
  -    return ap_pass_brigade(r->output_filters, bb);
  +        return ap_pass_brigade(r->output_filters, bb);
  +    }
  +    else {              /* unusual method (not GET or POST) */
  +        if (r->method_number == M_INVALID) {
  +            ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
  +                          "Invalid method in request %s", r->the_request);
  +            return HTTP_NOT_IMPLEMENTED;
  +        }
   
  +        if (r->method_number == M_OPTIONS) {
  +            return ap_send_http_options(r);
  +        }
  +        return HTTP_METHOD_NOT_ALLOWED;
  +    }
   }
   
   static int net_time_filter(ap_filter_t *f, apr_bucket_brigade *b,
  
  
  

Mime
View raw message