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

HttpHeaders.get() with more than one cookie returns garbage.

Moderators: kris

Posted: 05/31/09 04:16:55

Hi folks, This piece of code show that if we have the same HttpHeader? more than one twice, the HttpHeaders?.get() method will return garbage:

private void test()
	auto page = new HttpGet("");;
	Stdout(" ##### Not using HttpHeaders.get():").newline();
	foreach(header; page.getResponseHeaders())
		if ( == HttpHeader.SetCookie.value)

	Stdout("\r\n ##### Using HttpHeaders.get():").newline();
	foreach(header; page.getResponseHeaders().get(HttpHeader.SetCookie))

which returns:

 ##### Not using HttpHeaders.get():
Set-Cookie: ebay=%5Esbf%3D%23%5E;; Path=/
Set-Cookie: dp1=bspref/04de46a2d^u1p/QEBfX0BAX19AQA**4c0336ad^;; Expires=Tue, 31-May-2011 04:10:21 GMT; Path=/
Set-Cookie: nonsession=CgADLAAFKIgo1MQDKACBTiAStOTRkYzZhMTgxMjEwYTBiNThiMDU1MTQ1ZmZmNWQwM2EzRS0f;; Expires=Mon, 31-May-2010 04:10:21 GMT; Path=/
Set-Cookie: s=CgAD4ACBKI1StOTRkYzZhMTgxMjEwYTBiNThiMDU1MTQ1ZmZmNWQwMznoN3e9;; Path=/

 ##### Using HttpHeaders.get():
ebay=%5Esbf%3D%23%5E;; Path=/


AmBAr Amarelo

Author Message

Posted: 05/31/09 04:22:18

well, don't return garbage, but only returns one unique HttpHeader? and not all HttpHeader? with matched name.

the method get() should returns all of matched names and not only the first.


AmBAr Amarelo

Posted: 06/01/09 21:19:14

Well, returning more than one in a get() call would mean that you always would have to iterate over the results even if there was only one. I assume that this is the reason why the API is different for your use case, try:

foreach(header; page.getResponseHeaders().createFilter(HttpHeader.SetCookie))

The reason that the foreach works at all in your case is that the output from get is a string, and so you iterate over each character in it.