免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4813 | 回复: 0
打印 上一主题 下一主题

[Web] Nginx Post静态文件405的补丁 for nginx 0.8.31 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-12-28 09:48 |只看该作者 |倒序浏览
完全按照以前的补丁Copy paste出来的 分享给大家
form www.linuxtone.org/www.queryer.cn

  1. --- nginx-0.8.31/src/http/modules/ngx_http_dav_module.c        2009-10-06 17:32:21.000000000 +0800
  2. +++ nginx-0.8.31/src/http/modules/ngx_http_dav_module.c        2009-12-27 16:03:00.000000000 +0800
  3. @@ -219,7 +219,7 @@
  4.      ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  5.                     "http put filename: \"%s\"", path.data);

  6. -    temp = &r->request_body->temp_file->file.name;
  7. +    temp = &r->main->request_body->temp_file->file.name;

  8.      if (ngx_file_info(path.data, &fi) == NGX_FILE_ERROR) {
  9.          status = NGX_HTTP_CREATED;
  10. @@ -257,7 +257,7 @@

  11.          if (date != NGX_ERROR) {
  12.              ext.time = date;
  13. -            ext.fd = r->request_body->temp_file->file.fd;
  14. +            ext.fd = r->main->request_body->temp_file->file.fd;
  15.          }
  16.      }

  17. --- nginx-0.8.31/src/http/modules/ngx_http_static_module.c        2009-09-30 21:21:52.000000000 +0800
  18. +++ nginx-0.8.31/src/http/modules/ngx_http_static_module.c        2009-12-27 16:04:48.000000000 +0800
  19. @@ -197,14 +197,13 @@

  20. #endif

  21. -    if (r->method & NGX_HTTP_POST) {
  22. -        return NGX_HTTP_NOT_ALLOWED;
  23. -    }
  24. +    if (r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD)) {

  25.      rc = ngx_http_discard_request_body(r);
  26. -
  27. -    if (rc != NGX_OK) {
  28. -        return rc;
  29. +        if (rc != NGX_OK) {
  30. +            return rc;
  31. +        }
  32. +   
  33.      }

  34.      log->action = "sending response to client";
  35. --- nginx-0.8.31/src/http/modules/perl/nginx.xs        2009-11-12 23:50:34.000000000 +0800
  36. +++ nginx-0.8.31/src/http/modules/perl/nginx.xs        2009-12-27 16:09:52.000000000 +0800
  37. @@ -151,8 +151,8 @@
  38.      CODE:

  39.      dXSTARG;
  40. -    ngx_http_request_t  *r;
  41. -
  42. +    ngx_http_request_t       *r;
  43. +        ngx_http_request_body_t  *rb;
  44.      ngx_http_perl_set_request(r);

  45.      sv_upgrade(TARG, SVt_IV);
  46. @@ -389,20 +389,19 @@

  47.      ngx_http_perl_set_request(r);

  48. -    if (r->request_body == NULL
  49. -        || r->request_body->temp_file
  50. -        || r->request_body->bufs == NULL)
  51. -    {
  52. +    rb = r->main->request_body;
  53. +       
  54. +        if (rb == NULL || rb->temp_file || rb->bufs == NULL) {
  55.          XSRETURN_UNDEF;
  56.      }

  57. -    len = r->request_body->bufs->buf->last - r->request_body->bufs->buf->pos;
  58. +    len = rb->bufs->buf->last - rb->bufs->buf->pos;

  59.      if (len == 0) {
  60.          XSRETURN_UNDEF;
  61.      }

  62. -    ngx_http_perl_set_targ(r->request_body->bufs->buf->pos, len);
  63. +    ngx_http_perl_set_targ(rb->bufs->buf->pos, len);

  64.      ST(0) = TARG;

  65. @@ -412,16 +411,20 @@
  66.      CODE:

  67.      dXSTARG;
  68. -    ngx_http_request_t  *r;
  69. +    ngx_http_request_t       *r;
  70. +        ngx_http_request_body_t  *rb;

  71.      ngx_http_perl_set_request(r);

  72. -    if (r->request_body == NULL || r->request_body->temp_file == NULL) {
  73. +    rb = r->main->request_body;
  74. +       
  75. +        if (rb == NULL || rb->temp_file == NULL) {
  76.          XSRETURN_UNDEF;
  77.      }

  78. -    ngx_http_perl_set_targ(r->request_body->temp_file->file.name.data,
  79. -                           r->request_body->temp_file->file.name.len);
  80. +   
  81. +    ngx_http_perl_set_targ(rb->temp_file->file.name.data,
  82. +                        rb->temp_file->file.name.len);                     

  83.      ST(0) = TARG;

  84. --- nginx-0.8.31/src/http/ngx_http_core_module.c        2009-12-23 23:31:16.000000000 +0800
  85. +++ nginx-0.8.31/src/http/ngx_http_core_module.c        2009-12-27 15:42:36.000000000 +0800
  86. @@ -2073,9 +2073,7 @@
  87.      ngx_http_clear_accept_ranges(sr);
  88.      ngx_http_clear_last_modified(sr);

  89. -    sr->request_body = r->request_body;
  90. -
  91. -    sr->method = NGX_HTTP_GET;
  92. +        sr->method = r->method;
  93.      sr->http_version = r->http_version;

  94.      sr->request_line = r->request_line;
  95. @@ -2093,7 +2091,7 @@
  96.      sr->waited = (flags & NGX_HTTP_SUBREQUEST_WAITED) != 0;

  97.      sr->unparsed_uri = r->unparsed_uri;
  98. -    sr->method_name = ngx_http_core_get_method;
  99. +    sr->method_name = r->method_name;
  100.      sr->http_protocol = r->http_protocol;

  101.      ngx_http_set_exten(sr);
  102. --- nginx-0.8.31/src/http/ngx_http_request_body.c        2009-10-20 00:12:13.000000000 +0800
  103. +++ nginx-0.8.31/src/http/ngx_http_request_body.c        2009-12-27 15:59:42.000000000 +0800
  104. @@ -33,46 +33,49 @@
  105.      ngx_buf_t                 *b;
  106.      ngx_chain_t               *cl, **next;
  107.      ngx_temp_file_t           *tf;
  108. +        ngx_http_request_t        *mr;
  109.      ngx_http_request_body_t   *rb;
  110.      ngx_http_core_loc_conf_t  *clcf;

  111.      r->main->count++;

  112. -    if (r->request_body || r->discard_body) {
  113. +    mr = r->main;
  114. +       
  115. +        if (mr->request_body || mr->discard_body) {
  116.          post_handler(r);
  117.          return NGX_OK;
  118.      }

  119. -    if (ngx_http_test_expect(r) != NGX_OK) {
  120. +    if (ngx_http_test_expect(mr) != NGX_OK) {
  121.          return NGX_HTTP_INTERNAL_SERVER_ERROR;
  122.      }

  123. -    rb = ngx_pcalloc(r->pool, sizeof(ngx_http_request_body_t));
  124. +    rb = ngx_pcalloc(mr->pool, sizeof(ngx_http_request_body_t));
  125.      if (rb == NULL) {
  126.          return NGX_HTTP_INTERNAL_SERVER_ERROR;
  127.      }

  128. -    r->request_body = rb;
  129. +    mr->request_body = rb;

  130. -    if (r->headers_in.content_length_n < 0) {
  131. +    if (mr->headers_in.content_length_n < 0) {
  132.          post_handler(r);
  133.          return NGX_OK;
  134.      }

  135.      clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);

  136. -    if (r->headers_in.content_length_n == 0) {
  137. +    if (mr->headers_in.content_length_n == 0) {

  138.          if (r->request_body_in_file_only) {
  139. -            tf = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t));
  140. +            tf = ngx_pcalloc(mr->pool, sizeof(ngx_temp_file_t));
  141.              if (tf == NULL) {
  142.                  return NGX_HTTP_INTERNAL_SERVER_ERROR;
  143.              }

  144.              tf->file.fd = NGX_INVALID_FILE;
  145. -            tf->file.log = r->connection->log;
  146. +            tf->file.log = mr->connection->log;
  147.              tf->path = clcf->client_body_temp_path;
  148. -            tf->pool = r->pool;
  149. +            tf->pool = mr->pool;
  150.              tf->warn = "a client request body is buffered to a temporary file";
  151.              tf->log_level = r->request_body_file_log_level;
  152.              tf->persistent = r->request_body_in_persistent_file;
  153. @@ -107,27 +110,27 @@
  154.       *     rb->rest = 0;
  155.       */

  156. -    preread = r->header_in->last - r->header_in->pos;
  157. +    preread = mr->header_in->last - mr->header_in->pos;

  158.      if (preread) {

  159.          /* there is the pre-read part of the request body */

  160. -        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  161. +        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mr->connection->log, 0,
  162.                         "http client request body preread %uz", preread);

  163. -        b = ngx_calloc_buf(r->pool);
  164. +        b = ngx_calloc_buf(mr->pool);
  165.          if (b == NULL) {
  166.              return NGX_HTTP_INTERNAL_SERVER_ERROR;
  167.          }

  168.          b->temporary = 1;
  169. -        b->start = r->header_in->pos;
  170. -        b->pos = r->header_in->pos;
  171. -        b->last = r->header_in->last;
  172. -        b->end = r->header_in->end;
  173. +        b->start = mr->header_in->pos;
  174. +        b->pos = mr->header_in->pos;
  175. +        b->last = mr->header_in->last;
  176. +        b->end = mr->header_in->end;

  177. -        rb->bufs = ngx_alloc_chain_link(r->pool);
  178. +        rb->bufs = ngx_alloc_chain_link(mr->pool);
  179.          if (rb->bufs == NULL) {
  180.              return NGX_HTTP_INTERNAL_SERVER_ERROR;
  181.          }
  182. @@ -137,15 +140,15 @@

  183.          rb->buf = b;

  184. -        if ((off_t) preread >= r->headers_in.content_length_n) {
  185. +        if ((off_t) preread >= mr->headers_in.content_length_n) {

  186.              /* the whole request body was pre-read */

  187. -            r->header_in->pos += (size_t) r->headers_in.content_length_n;
  188. -            r->request_length += r->headers_in.content_length_n;
  189. +            mr->header_in->pos += (size_t) mr->headers_in.content_length_n;
  190. +           mr->request_length += mr->headers_in.content_length_n;

  191. -            if (r->request_body_in_file_only) {
  192. -                if (ngx_http_write_request_body(r, rb->bufs) != NGX_OK) {
  193. +            if (mr->request_body_in_file_only) {
  194. +                if (ngx_http_write_request_body(mr, rb->bufs) != NGX_OK) {
  195.                      return NGX_HTTP_INTERNAL_SERVER_ERROR;
  196.                  }
  197.              }
  198. @@ -159,11 +162,11 @@
  199.           * to not consider the body as pipelined request in
  200.           * ngx_http_set_keepalive()
  201.           */
  202. -        r->header_in->pos = r->header_in->last;
  203. +        mr->header_in->pos = mr->header_in->last;

  204. -        r->request_length += preread;
  205. +        mr->request_length += preread;

  206. -        rb->rest = r->headers_in.content_length_n - preread;
  207. +        rb->rest = mr->headers_in.content_length_n - preread;

  208.          if (rb->rest <= (off_t) (b->end - b->last)) {

  209. @@ -180,7 +183,7 @@

  210.      } else {
  211.          b = NULL;
  212. -        rb->rest = r->headers_in.content_length_n;
  213. +        rb->rest = mr->headers_in.content_length_n;
  214.          next = &rb->bufs;
  215.      }

  216. @@ -201,12 +204,12 @@
  217.          b = NULL;
  218.      }

  219. -    rb->buf = ngx_create_temp_buf(r->pool, size);
  220. +    rb->buf = ngx_create_temp_buf(mr->pool, size);
  221.      if (rb->buf == NULL) {
  222.          return NGX_HTTP_INTERNAL_SERVER_ERROR;
  223.      }

  224. -    cl = ngx_alloc_chain_link(r->pool);
  225. +    cl = ngx_alloc_chain_link(mr->pool);
  226.      if (cl == NULL) {
  227.          return NGX_HTTP_INTERNAL_SERVER_ERROR;
  228.      }
  229. @@ -251,7 +254,7 @@
  230.      rc = ngx_http_do_read_client_request_body(r);

  231.      if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
  232. -        ngx_http_finalize_request(r, rc);
  233. +        ngx_http_finalize_request(r->main, rc);
  234.      }
  235. }

  236. @@ -263,11 +266,13 @@
  237.      ssize_t                    n;
  238.      ngx_buf_t                 *b;
  239.      ngx_connection_t          *c;
  240. +        ngx_http_request_t        *mr;
  241.      ngx_http_request_body_t   *rb;
  242.      ngx_http_core_loc_conf_t  *clcf;

  243.      c = r->connection;
  244. -    rb = r->request_body;
  245. +    mr = r->main;
  246. +    rb = mr->request_body;

  247.      ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
  248.                     "http read client request body");
  249. @@ -276,7 +281,7 @@
  250.          for ( ;; ) {
  251.              if (rb->buf->last == rb->buf->end) {

  252. -                if (ngx_http_write_request_body(r, rb->to_write) != NGX_OK) {
  253. +                if (ngx_http_write_request_body(mr, rb->to_write) != NGX_OK) {
  254.                      return NGX_HTTP_INTERNAL_SERVER_ERROR;
  255.                  }

  256. @@ -311,7 +316,7 @@

  257.              rb->buf->last += n;
  258.              rb->rest -= n;
  259. -            r->request_length += n;
  260. +            mr->request_length += n;

  261.              if (rb->rest == 0) {
  262.                  break;
  263. @@ -349,7 +354,7 @@

  264.          /* save the last part */

  265. -        if (ngx_http_write_request_body(r, rb->to_write) != NGX_OK) {
  266. +        if (ngx_http_write_request_body(mr, rb->to_write) != NGX_OK) {
  267.              return NGX_HTTP_INTERNAL_SERVER_ERROR;
  268.          }

  269. --- nginx-0.8.31/src/http/ngx_http_request.c        2009-11-16 20:19:02.000000000 +0800
  270. +++ nginx-0.8.31/src/http/ngx_http_request.c        2009-12-27 15:40:46.000000000 +0800
  271. @@ -2369,6 +2369,18 @@
  272.          r->lingering_time = ngx_time() + (time_t) (clcf->lingering_time / 1000);
  273.          ngx_add_timer(rev, clcf->lingering_timeout);
  274.          return;
  275. +               
  276. +                } else {
  277. +                r->expect_tested = 1;
  278. +               
  279. +                if (ngx_http_discard_request_body(r) != NGX_OK) {
  280. +                        ngx_http_close_connection(c);
  281. +                        return;
  282. +                }
  283. +               
  284. +                if (r->discard_body) {
  285. +                        return;
  286. +                }
  287.      }

  288.      c->log->action = "closing request";
  289. --- nginx-0.8.31/src/http/ngx_http_upstream.c        2009-12-23 23:31:16.000000000 +0800
  290. +++ nginx-0.8.31/src/http/ngx_http_upstream.c        2009-12-27 15:48:32.000000000 +0800
  291. @@ -470,8 +470,8 @@
  292.          r->write_event_handler = ngx_http_upstream_wr_check_broken_connection;
  293.      }

  294. -    if (r->request_body) {
  295. -        u->request_bufs = r->request_body->bufs;
  296. +        if (r->main->request_body) {
  297. +                u->request_bufs = r->main->request_body->bufs;
  298.      }

  299.      if (u->create_request(r) != NGX_OK) {
  300. @@ -1033,9 +1033,10 @@
  301. static void
  302. ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u)
  303. {
  304. -    ngx_int_t          rc;
  305. -    ngx_time_t        *tp;
  306. -    ngx_connection_t  *c;
  307. +        ngx_int_t                 rc;
  308. +        ngx_time_t               *tp;
  309. +        ngx_connection_t         *c;
  310. +        ngx_http_request_body_t  *rb;

  311.      r->connection->log->action = "connecting to upstream";

  312. @@ -1119,11 +1120,10 @@
  313.          }
  314.      }

  315. -    if (r->request_body
  316. -        && r->request_body->buf
  317. -        && r->request_body->temp_file
  318. -        && r == r->main)
  319. -    {
  320. +    rb = r->main->request_body;
  321. +       
  322. +        if (r == r->main && rb && rb->buf && rb->temp_file) {
  323. +       
  324.          /*
  325.           * the r->request_body->buf can be reused for one request only,
  326.           * the subrequests should allocate their own temporay bufs
  327. @@ -1136,13 +1136,13 @@
  328.              return;
  329.          }

  330. -        u->output.free->buf = r->request_body->buf;
  331. +        u->output.free->buf = rb->buf;
  332.          u->output.free->next = NULL;
  333.          u->output.allocated = 1;

  334. -        r->request_body->buf->pos = r->request_body->buf->start;
  335. -        r->request_body->buf->last = r->request_body->buf->start;
  336. -        r->request_body->buf->tag = u->output.tag;
  337. +        rb->buf->pos = rb->buf->start;
  338. +        rb->buf->last = rb->buf->start;
  339. +        rb->buf->tag = u->output.tag;
  340.      }

  341.      u->request_sent = 0;
  342. @@ -1263,8 +1263,8 @@

  343.      /* reinit the subrequest's ngx_output_chain() context */

  344. -    if (r->request_body && r->request_body->temp_file
  345. -        && r != r->main && u->output.buf)
  346. +    if (r != r->main && u->output.buf
  347. +       && r->main->request_body && r->main->request_body->temp_file)
  348.      {
  349.          u->output.free = ngx_alloc_chain_link(r->pool);
  350.          if (u->output.free == NULL) {
  351. @@ -1970,6 +1970,7 @@
  352.      ngx_int_t                  rc;
  353.      ngx_event_pipe_t          *p;
  354.      ngx_connection_t          *c;
  355. +        ngx_http_request_body_t   *rb;
  356.      ngx_http_core_loc_conf_t  *clcf;

  357.      rc = ngx_http_send_header(r);
  358. @@ -2002,9 +2003,11 @@

  359.      u->header_sent = 1;

  360. -    if (r->request_body && r->request_body->temp_file) {
  361. -        ngx_pool_run_cleanup_file(r->pool, r->request_body->temp_file->file.fd);
  362. -        r->request_body->temp_file->file.fd = NGX_INVALID_FILE;
  363. +    rb = r->main->request_body;
  364. +       
  365. +        if (rb && rb->temp_file) {
  366. +                ngx_pool_run_cleanup_file(r->pool, rb->temp_file->file.fd);
  367. +                rb->temp_file->file.fd = NGX_INVALID_FILE;
  368.      }

  369.      clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
  370. --- nginx-0.8.31/src/http/ngx_http_variables.c        2009-11-23 21:13:58.000000000 +0800
  371. +++ nginx-0.8.31/src/http/ngx_http_variables.c        2009-12-27 16:01:58.000000000 +0800
  372. @@ -1601,17 +1601,21 @@
  373. ngx_http_variable_request_body_file(ngx_http_request_t *r,
  374.      ngx_http_variable_value_t *v, uintptr_t data)
  375. {
  376. -    if (r->request_body == NULL || r->request_body->temp_file == NULL) {
  377. +    ngx_http_request_body_t  *rb;
  378. +       
  379. +        rb = r->request_body;
  380. +       
  381. +        if (rb == NULL || rb->temp_file == NULL) {
  382.          v->not_found = 1;

  383.          return NGX_OK;
  384.      }

  385. -    v->len = r->request_body->temp_file->file.name.len;
  386. +    v->len = rb->temp_file->file.name.len;
  387.      v->valid = 1;
  388.      v->no_cacheable = 0;
  389.      v->not_found = 0;
  390. -    v->data = r->request_body->temp_file->file.name.data;
  391. +    v->data = rb->temp_file->file.name.data;

  392.      return NGX_OK;
  393. }


复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP