Re: Sending headers

 >"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;
      /* ... */
  };

  int
  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;
  }

  void
  Connect::www_lib_init(bool www_verbose_errors, bool accept_deflate)
  {
  .
  .
  .
      HTHeader_addGenerator(xdods_accept_types_header_gen);
  }

James

-- 
__________________________________________________________________________
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