LCOV - code coverage report
Current view: top level - home/agentz/git/echo-nginx-module/src - ngx_http_echo_location.c (source / functions) Hit Total Coverage
Test: foo.info Lines: 31 69 44.9 %
Date: 2011-05-12 Functions: 2 3 66.7 %
Branches: 11 42 26.2 %

           Branch data     Line data    Source code
       1                 :            : #define DDEBUG 0
       2                 :            : #include "ddebug.h"
       3                 :            : 
       4                 :            : #include "ngx_http_echo_util.h"
       5                 :            : #include "ngx_http_echo_location.h"
       6                 :            : #include "ngx_http_echo_handler.h"
       7                 :            : 
       8                 :            : #include <nginx.h>
       9                 :            : 
      10                 :            : 
      11                 :            : static ngx_int_t ngx_http_echo_adjust_subrequest(ngx_http_request_t *sr);
      12                 :            : 
      13                 :            : 
      14                 :            : ngx_int_t
      15                 :          0 : ngx_http_echo_exec_echo_location_async(ngx_http_request_t *r,
      16                 :            :         ngx_http_echo_ctx_t *ctx, ngx_array_t *computed_args)
      17                 :            : {
      18                 :            :     ngx_int_t                    rc;
      19                 :            :     ngx_http_request_t          *sr; /* subrequest object */
      20                 :            :     ngx_str_t                   *computed_arg_elts;
      21                 :            :     ngx_str_t                    location;
      22                 :            :     ngx_str_t                   *url_args;
      23                 :            :     ngx_str_t                    args;
      24                 :          0 :     ngx_uint_t                   flags = 0;
      25                 :            : 
      26                 :            : 
      27                 :            :     dd_enter();
      28                 :            : 
      29                 :          0 :     computed_arg_elts = computed_args->elts;
      30                 :            : 
      31                 :          0 :     location = computed_arg_elts[0];
      32                 :            : 
      33         [ #  # ]:          0 :     if (location.len == 0) {
      34                 :          0 :         return NGX_HTTP_INTERNAL_SERVER_ERROR;
      35                 :            :     }
      36                 :            : 
      37         [ #  # ]:          0 :     if (computed_args->nelts > 1) {
      38                 :          0 :         url_args = &computed_arg_elts[1];
      39                 :            :     } else {
      40                 :          0 :         url_args = NULL;
      41                 :            :     }
      42                 :            : 
      43                 :          0 :     args.data = NULL;
      44                 :          0 :     args.len = 0;
      45                 :            : 
      46         [ #  # ]:          0 :     if (ngx_http_parse_unsafe_uri(r, &location, &args, &flags) != NGX_OK) {
      47                 :          0 :         ctx->headers_sent = 1;
      48                 :          0 :         return NGX_HTTP_INTERNAL_SERVER_ERROR;
      49                 :            :     }
      50                 :            : 
      51 [ #  # ][ #  # ]:          0 :     if (args.len > 0 && url_args == NULL) {
      52                 :          0 :         url_args = &args;
      53                 :            :     }
      54                 :            : 
      55                 :          0 :     rc = ngx_http_echo_send_header_if_needed(r, ctx);
      56         [ #  # ]:          0 :     if (r->header_only) {
      57                 :          0 :         return NGX_HTTP_INTERNAL_SERVER_ERROR;
      58                 :            :     }
      59                 :            : 
      60         [ #  # ]:          0 :     if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
      61                 :          0 :         return rc;
      62                 :            :     }
      63                 :            : 
      64                 :          0 :     rc = ngx_http_subrequest(r, &location, url_args, &sr, NULL, 0);
      65                 :            : 
      66         [ #  # ]:          0 :     if (rc != NGX_OK) {
      67                 :          0 :         return NGX_ERROR;
      68                 :            :     }
      69                 :            : 
      70                 :          0 :     rc = ngx_http_echo_adjust_subrequest(sr);
      71         [ #  # ]:          0 :     if (rc != NGX_OK) {
      72                 :          0 :         return NGX_ERROR;
      73                 :            :     }
      74                 :            : 
      75                 :          0 :     return NGX_OK;
      76                 :            : }
      77                 :            : 
      78                 :            : 
      79                 :            : ngx_int_t
      80                 :          2 : ngx_http_echo_exec_echo_location(ngx_http_request_t *r,
      81                 :            :         ngx_http_echo_ctx_t *ctx, ngx_array_t *computed_args)
      82                 :            : {
      83                 :            :     ngx_int_t                            rc;
      84                 :            :     ngx_http_request_t                  *sr; /* subrequest object */
      85                 :            :     ngx_str_t                           *computed_arg_elts;
      86                 :            :     ngx_str_t                            location;
      87                 :            :     ngx_str_t                           *url_args;
      88                 :            :     ngx_http_post_subrequest_t          *psr;
      89                 :            :     ngx_str_t                            args;
      90                 :          2 :     ngx_uint_t                           flags = 0;
      91                 :            : 
      92                 :            : 
      93                 :            :     dd_enter();
      94                 :            : 
      95                 :          2 :     computed_arg_elts = computed_args->elts;
      96                 :            : 
      97                 :          2 :     location = computed_arg_elts[0];
      98                 :            : 
      99         [ -  + ]:          2 :     if (location.len == 0) {
     100                 :          0 :         return NGX_HTTP_INTERNAL_SERVER_ERROR;
     101                 :            :     }
     102                 :            : 
     103         [ -  + ]:          2 :     if (computed_args->nelts > 1) {
     104                 :          0 :         url_args = &computed_arg_elts[1];
     105                 :            :     } else {
     106                 :          2 :         url_args = NULL;
     107                 :            :     }
     108                 :            : 
     109                 :          2 :     args.data = NULL;
     110                 :          2 :     args.len = 0;
     111                 :            : 
     112         [ -  + ]:          2 :     if (ngx_http_parse_unsafe_uri(r, &location, &args, &flags) != NGX_OK) {
     113                 :          0 :         ctx->headers_sent = 1;
     114                 :          0 :         return NGX_HTTP_INTERNAL_SERVER_ERROR;
     115                 :            :     }
     116                 :            : 
     117 [ -  + ][ #  # ]:          2 :     if (args.len > 0 && url_args == NULL) {
     118                 :          0 :         url_args = &args;
     119                 :            :     }
     120                 :            : 
     121                 :          2 :     rc = ngx_http_echo_send_header_if_needed(r, ctx);
     122                 :            : 
     123 [ +  - ][ -  + ]:          2 :     if (r->header_only || rc >= NGX_HTTP_SPECIAL_RESPONSE) {
     124                 :          0 :         return rc;
     125                 :            :     }
     126                 :            : 
     127                 :          2 :     psr = ngx_palloc(r->pool, sizeof(ngx_http_post_subrequest_t));
     128                 :            : 
     129         [ -  + ]:          2 :     if (psr == NULL) {
     130                 :          0 :         return NGX_HTTP_INTERNAL_SERVER_ERROR;
     131                 :            :     }
     132                 :            : 
     133                 :          2 :     psr->handler = ngx_http_echo_post_subrequest;
     134                 :          2 :     psr->data = ctx;
     135                 :            : 
     136                 :          2 :     rc = ngx_http_subrequest(r, &location, url_args, &sr, psr, 0);
     137                 :            : 
     138         [ -  + ]:          2 :     if (rc != NGX_OK) {
     139                 :          0 :         return NGX_ERROR;
     140                 :            :     }
     141                 :            : 
     142                 :          2 :     rc = ngx_http_echo_adjust_subrequest(sr);
     143                 :            : 
     144         [ -  + ]:          2 :     if (rc != NGX_OK) {
     145                 :          0 :         return NGX_ERROR;
     146                 :            :     }
     147                 :            : 
     148                 :          2 :     return NGX_AGAIN;
     149                 :            : }
     150                 :            : 
     151                 :            : 
     152                 :            : static ngx_int_t
     153                 :          2 : ngx_http_echo_adjust_subrequest(ngx_http_request_t *sr)
     154                 :            : {
     155                 :            :     ngx_http_core_main_conf_t   *cmcf;
     156                 :            :     ngx_http_request_t          *r;
     157                 :            : 
     158                 :            : 
     159                 :            :     /* we do not inherit the parent request's variables */
     160                 :          2 :     cmcf = ngx_http_get_module_main_conf(sr, ngx_http_core_module);
     161                 :            : 
     162                 :          2 :     r = sr->parent;
     163                 :            : 
     164                 :          2 :     sr->header_in = r->header_in;
     165                 :            : 
     166                 :            :     /* XXX work-around a bug in ngx_http_subrequest */
     167         [ +  - ]:          2 :     if (r->headers_in.headers.last == &r->headers_in.headers.part) {
     168                 :          2 :         sr->headers_in.headers.last = &sr->headers_in.headers.part;
     169                 :            :     }
     170                 :            : 
     171                 :          2 :     sr->variables = ngx_pcalloc(sr->pool, cmcf->variables.nelts
     172                 :            :                                         * sizeof(ngx_http_variable_value_t));
     173                 :            : 
     174         [ -  + ]:          2 :     if (sr->variables == NULL) {
     175                 :          0 :         return NGX_HTTP_INTERNAL_SERVER_ERROR;
     176                 :            :     }
     177                 :            : 
     178                 :          2 :     return NGX_OK;
     179                 :            : }
     180                 :            : 

Generated by: LCOV version 1.9