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: Writing apache module to do chunked encoding
Author
lmertens



Joined: 26 Apr 2013
Posts: 1
Location: California

PostPosted: Fri 17 May '13 20:46    Post subject: Writing apache module to do chunked encoding Reply with quote

Post moved to the correct forum. The forum description was not that clear, so changed it.

Hi friends, I am an Apache newb writing an Apache module that returns content with chunked encoding. I could not find much material on how to actually implement this. After reading the HTTP 1.1 spec for chunked encoding I've come up with some prototype code that I put in the module handler function and it seems to work and return what looks like valid content when I tested it with curl. Does this look ok or is there anything else I need to do or watch out for? Thanks for your help.

Code:


static int hello_handler(request_rec *r)
{
  ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0, r->server,
  "mod_hello: %s", "Before content is output");

  ap_set_content_type(r, "text/plain");

  if (r->header_only) {
    return OK;
  }

  r->chunked = 1;

  ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0, r->server,
  "mod_hello: %s", "Before first print");

  ap_rputs("7\nHello 1\n",r);
  ap_rflush(r);
  sleep(5);

  ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0, r->server,
  "mod_hello: %s", "Before second print");

  ap_rputs("8\n Hello 2\n",r);
  ap_rputs("0\n\n",r);

  return OK;
}

Back to top


Reply to topic   Topic: Writing apache module to do chunked encoding View previous topic :: View next topic
Post new topic   Forum Index -> Building & Member Downloads