logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Building & Member Downloads View previous topic :: View next topic
Reply to topic   Topic: Getting the content of a request GET XXX Host:XXX Content...
Author
guillaume.chevet



Joined: 04 Dec 2009
Posts: 3

PostPosted: Fri 04 Dec '09 11:33    Post subject: Getting the content of a request GET XXX Host:XXX Content... Reply with quote

Hello,

I'm develloping a web-service as an apache module in C. I'm trying to test it with telnet but i don't know how I kann access some information.

I open telnet (telnet localhost 80) and paste the following text:
"
GET /MYTEST
HTTP/1.1
Host: myhost.test.de:8180
Accept: */*
Accept-Encoding: deflate, gzip
Content-type:text/plain; charset=utf-8
Content-Length: 29

address=mytest@kunde.de
"

How kann I access all these information with the request_rec object?

Thanks a lot,
Guillaume
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7373
Location: Germany, Next to Hamburg

PostPosted: Fri 04 Dec '09 13:26    Post subject: Reply with quote

A very simple and short module is mod_echo. It does what the name says it simply echos what you send to it. So I think it can be a good start for to look into that module.

http://svn.apache.org/repos/asf/httpd/httpd/branches/2.2.x/modules/echo/mod_echo.c
Back to top
guillaume.chevet



Joined: 04 Dec 2009
Posts: 3

PostPosted: Mon 07 Dec '09 12:44    Post subject: Reply with quote

Thank a lot!

I found 2 way to read the headers. With the first way I cant read the body:

/* Functions to Write the HEADER_IN CONTENT
* Call dump_request(r);
*/
int iterate_func(void *req, const char *key, const char *value) {
fprintf(stderr,"iterate_func :\n");
int stat;
char *line;
request_rec *r = (request_rec *)req;
if (key == NULL || value == NULL || value[0] == '\0')
return 1;
fprintf(stderr, "%s => %s\n", key, value);
fflush(stderr);

return 1;
}

static int dump_request(request_rec *r) {
fprintf(stderr,"dump_request :\n");

ap_set_content_type(r, "text/plain");

if (apr_is_empty_table(r->headers_in))
{
fprintf(stderr,"EMPTY");
fflush(stderr);
}



apr_table_do(iterate_func, r, r->headers_in, NULL);
fprintf(stderr,"dump_request :\n");

return OK;
}

------------The second way-----------------
static int mod_mymethod_handler(conn_rec *c)
{
apr_bucket_brigade *brigade = NULL;
apr_bucket *bucket = NULL;
int seen_eos = 0;
int seen_body = 0;

apr_status_t rc;

//Initialize the brigade object
brigade = apr_brigade_create(c->pool, c->bucket_alloc);

do //for each line of the request
{
// Get the input from the client
if (((rc = ap_get_brigade(c->input_filters, brigade, AP_MODE_GETLINE, APR_BLOCK_READ, 0)) != APR_SUCCESS) || APR_BRIGADE_EMPTY(brigade))
{
apr_brigade_destroy(brigade);
break;
}

//For each element (buckets) from the input (brigade)
for (bucket = APR_BRIGADE_FIRST(brigade); bucket != APR_BRIGADE_SENTINEL(brigade); bucket = APR_BUCKET_NEXT(bucket))
{
char *data;
apr_size_t len;
int i;

if (APR_BUCKET_IS_EOS(bucket))
{
seen_eos = 1;
break;
}

rc = apr_bucket_read(bucket, &data, &len, APR_BLOCK_READ);

if (rc != APR_SUCCESS)
{
break;
}

//Parse the data
char *position = strchr(data, '\n');
int length = strlen(data)-strlen(position);
char *result = (char *)malloc((length+1)*sizeof(char));

strncpy(result, data, length);

result[length] = '\0';

fprintf(stderr,"\n gefunden = %s \n", result);
fflush(stderr);
free(result);


}

apr_brigade_cleanup(brigade);

} while (!seen_eos); //Wait for the end of the request

apr_brigade_destroy(brigade);
Back to top


Reply to topic   Topic: Getting the content of a request GET XXX Host:XXX Content... View previous topic :: View next topic
Post new topic   Forum Index -> Building & Member Downloads