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

RE: Problems with data POST

From: Michel Philip <mphilip@infovista.com>
Date: Thu, 31 Jan 2002 05:26:51 -0500 (EST)
Message-ID: <F520B214418AD4119F7000508BD90CC294B99A@hq01sr02.infovista.com>
To: "'www-lib@w3.org'" <www-lib@w3.org>
> I believe the keep-alive will "hold the line" 
> even after all the data is received.

Starting that the server answer HTTP/1.1 I aggree
with your analyse.

To have the terminate callback been called despite that
the lib must parse at the HTTP headers.

For this the output_format must be anything except WWW_RAW.

To have the lib parsing only HTTP headers but not the content
the output_format is WWW_SOURCE.

/mph

-----Original Message-----
From: Rob Corell [mailto:rcorell@adobe.com]
Sent: Tuesday, January 22, 2002 8:04 PM
To: Alik Kurdjukov; www-lib@w3.org
Subject: RE: Problems with data POST



	I had the same problem.  I believe the keep-alive will "hold the
line" even
after all the data is received.  The way I worked around it was kind of
complex (involving rewriting the event loop to not block), but the general
problem is that the library doesn't know the POST response is done because
the server doesn't close the socket.

	IIS will return the response length in the header, so I think you
can hook
the READ callback and kill the request when you've read the declared content
length worth of data.  Apache doesn't always include the content length in
the header, but if not it embeds the content length as an ASCII hex value as
the first line of the content.  This is--amazingly--in addition to the real
response.

	Example:
	0x38 0x62 0x20 0x0d 0x0a == "8b \r\n" for a 139 byte long response

	You can parse this out and use it to decide when to kill the
request.  And
you probably should, since you probably weren't expecting a bunch of garbage
at the beginning of the response anyway.

	-Rob


> -----Original Message-----
> From: www-lib-request@w3.org [mailto:www-lib-request@w3.org]On Behalf Of
> Alik Kurdjukov
> Sent: Tuesday, January 22, 2002 12:41 PM
> To: www-lib@w3.org
> Subject: Problems with data POST
>
>
> Hello!
>
> I'm posting some data (in message body) to the server, that supports
> keep-alive. The posting works fine, server replies immidiately. But I
> have some strange timeout (about 10 seconds) from last bytes read to
> call of terminate_handler. The status returned to the handler is -1, but
> the result chunk is correct. What's wrong? Maybe I need to set some
> timeout or something?
>
> I have the following code to get data from server:
> ===========
> PRIVATE int terminate_handler (HTRequest * request, HTResponse *
> response,
>                                void * param, int status)
> {
> 	HTEventList_stopLoop ();
>
> 	return 0;
> }
>
>
> PUBLIC HTChunk * HTPostAnchorToChunk(HTParentAnchor *  source, HTAnchor*
> destination, HTRequest* request)
> {
> 	if (source && destination && request) {
> 		HTChunk * chunk = NULL;
> 		HTStream * target = HTStreamToChunk(request, &chunk,
> -1);
> 		HTRequest_setOutputStream(request, target);
> 		if (HTPostAnchor(source, destination, request) != NULL)
> 			return chunk;
> 		else {
> 			HTChunk_delete(chunk);
> 			return NULL;
> 		}
> 	}
> 	return NULL;
> }
>
> int main (int argc, char ** argv)
> {
> 	HTRequest * request = NULL;
> 	HTParentAnchor * src = NULL;
> 	HTAnchor * dst = NULL;
> 	HTAnchor * anchor = NULL;
>     char * dst_str = NULL;
>     char * xml_data = NULL;
>     BOOL status = NO;
>
> 	HTProfile_newNoCacheClient("libwww-POST", "1.0");
>
>     //HTSetTraceMessageMask("sop");
>
>     HTPrint_setCallback(printer);
>     HTTrace_setCallback(tracer);
>
> 	HTNet_addAfter(terminate_handler, NULL, NULL, HT_ALL,
> HT_FILTER_LAST);
>
> 	if (argc >= 2) {
> 		dst_str = argv[1];
> 	} else {
>         HTPrint("Type the URI of the destination you want to POST.\n");
>         HTPrint("\t%s <destination>\n", argv[0]);
>         HTPrint("For example, %s http://myserver/destination.html\n",
> argv[0]);
> 		return -1;
>     }
>
>     if (dst_str && *dst_str) {
> 		char message[10000];
>
> 		long readBytes;
> 		FILE* f = fopen("request", "rb");
> 		if (!f) {
> 			printf("Error opening request file!\n");
> 			return 0;
> 		}
> 		readBytes = fread(message, 1, 10000, f);
> 		if (readBytes == 10000) {
> 			HTPrint("Too large file\n");
> 			return -1;
> 		}
> 		fclose(f);
>
> 		char * cwd = HTGetCurrentDirectoryURL();
> 		request = HTRequest_new();
> 		HTRequest_setOutputFormat(request, WWW_RAW);
>
> 		anchor = HTAnchor_findAddress(dst_str);
>
> 		src = HTTmpAnchor(NULL);
> 		HTAnchor_setDocument(src, message);
> 		HTAnchor_setFormat(src, HTAtom_for("text/xml"));
> 		HTAnchor_setCharset(src, HTAtom_for("UTF-8"));
> 		HTAnchor_setLength(src, readBytes);
>
> 		result = HTPostAnchorToChunk(src, anchor, request);
>
> 		if (!result)
> 		{
> 			printf ("NULL Response!!\n");
> 		}
> 		else
> 		{
> 			HTEventList_loop(request);
>
> 			HTPrint("---Printing response---->%s",
> HTChunk_data(result));
> 			HTChunk_delete(result);
> 		}
>
> 		HTRequest_delete(request);
>
> 		HTProfile_delete();
> 	}
> 	return 0;
> }
> ===========
>
> I'm posting some data to the server. The log on the screen looks like
> following:
> ===========
> Looking up jurgen
> Looking up jurgen
> Contacting jurgen
> Writing 1Kbytes
> Writing 1Kbytes
> Reading...
> Reading...
> Reading...
> Reading...
> ===========
>
>
> Best regards,
> Alik.
>
Received on Thursday, 31 January 2002 09:11:44 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 23 April 2007 18:18:40 GMT