Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

HttpClient suggestion

Moderators: kris

Posted: 12/08/07 17:58:43

I was very surprised to find out that HttpClient?.read takes a 'length' parameter from the user, but don't actually use it and returns whatever is in the socket no matter how longer it is than the requested length. I don't know if this is right, because I am not very experienced with HTTP, but I find this behavior very strange and useless. So here is what I did. This function reads the input and gives the sink exactly the length requested (or less, if eof is found). Notice, that the HttpClient?.input member is private (which I also find wrong), so this function needs the buffer that is returned by HttpClient?.open ...

class HttpClient2 : HttpClient
	this (RequestMethod method, char[] url){super(method, url);}

	bool read2 (void delegate (void[]) sink, long length,IBuffer input)
		while(length>input.readable) if(input.fill(input.input) == break;
		bool ret=length<=input.readable;
		return ret;

This is a suggestion for improvement of HttpClient? by the way :)

Author Message

Posted: 12/08/07 20:19:43

You're right ... it didn't respect the tail correctly. Should do now :)