File: mod_eat_post.c

package info (click to toggle)
apache2 2.4.65-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 59,148 kB
  • sloc: ansic: 211,971; python: 13,977; perl: 11,307; sh: 7,102; php: 1,315; javascript: 1,314; awk: 749; makefile: 712; lex: 374; yacc: 161; xml: 2
file content (61 lines) | stat: -rw-r--r-- 1,370 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#if CONFIG_FOR_HTTPD_TEST

<Location /eat_post>
   SetHandler eat_post
</Location>

#endif

#define APACHE_HTTPD_TEST_HANDLER eat_post_handler

#include "apache_httpd_test.h"

/* like mod_echo_post.c but does not echo back the data,
 * just sends back the number of bytes read
 */
static int eat_post_handler(request_rec *r)
{
    int rc;
    long nrd, total = 0;
#ifdef APACHE1
    char buff[IOBUFSIZE];
#else
    char buff[AP_IOBUFSIZE];
#endif

    if (strcmp(r->handler, "eat_post")) {
        return DECLINED;
    }
    if ((r->method_number != M_POST) && (r->method_number != M_PUT)) {
        return DECLINED;
    }

    if ((rc = ap_setup_client_block(r, REQUEST_CHUNKED_ERROR)) != OK) {
#ifdef APACHE1
        ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, r->server,
                     "[mod_eat_post] ap_setup_client_block failed: %d", rc);
#else
        ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r->server,
                     "[mod_eat_post] ap_setup_client_block failed: %d", rc);
#endif /* APACHE1 */
        return rc;
    }

    if (!ap_should_client_block(r)) {
        return OK;
    }

#ifdef APACHE1
    ap_send_http_header(r);
#endif
    
    while ((nrd = ap_get_client_block(r, buff, sizeof(buff))) > 0) {
        total += nrd;
    }

    ap_rprintf(r, "%ld\n", total);
    
    return OK;
}

APACHE_HTTPD_TEST_MODULE(eat_post);