W3C home > Mailing lists > Public > www-lib@w3.org > January to March 1999

Re: Sending headers

From: James Gallagher <jimg@dcz.dods.org>
Date: Tue, 16 Mar 1999 08:31:55 -0800 (PST)
Message-ID: <14062.34683.143111.546970@dcz.dods.org>
To: "Gert Koning" <koningj@sol1.unisa.ac.za>
CC: www-lib@w3.org
 >"Gert" == Gert Koning <koningj@sol1.unisa.ac.za> writes:

 > Hi all
 > With libwww, how can I send my own headers along with a request? Or can only
 > standard headers be sent? I would like to send a cookie with my request, as
 > if it was coming from a browser. I know cookies are not supported by libwww
 > (yet).

Here's how I do it (I'm posting this to the list in case there's a better
way). First I define a function that takes HTRequest and HTStream objects and
inserts the new header into the stream. Then, down in the code that
initializes libwww, I call HTHeader_addGenerator() passing it that function.
Note that I'm using the library from C++ but I don't think that affects this
any. Here's the code with other parts stripped away:

  #define PUTBLOCK(b, l)	(*target->isa->put_block)(target, b, l)
  struct _HTStream {
      const HTStreamClass *	isa;
      /* ... */

  xdods_accept_types_header_gen(HTRequest *pReq, HTStream *target)
      Connect *me = (Connect *)HTRequest_context(pReq);

      String types = "XDODS-Accept-Types: " + me->get_accept_types() + "\r\n";
      if (WWWTRACE) 
	  HTTrace("DODS..... '%s'.\n", types.chars());

      PUTBLOCK(types.chars(), types.length());

      return HT_OK;

  Connect::www_lib_init(bool www_verbose_errors, bool accept_deflate)


James Gallagher		         The Distributed Oceanographic Data System
jgallagher@gso.uri.edu               http://unidata.ucar.edu/packages/dods
Voice: 541.757.7992					 Fax: 541.758.3254
Received on Tuesday, 16 March 1999 11:32:40 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:33:49 UTC