Discussion:
WinHttp closes the connetion if it gets HTTP 404/304 status
(too old to reply)
Ram
2008-06-02 09:52:00 UTC
Permalink
Hi,
Although Connection: "Keep-Alive" header is present, my WinHttp client
drops a connetion if it gets HTTP response 404(file not found) or 304(file
not modified) and the same is maintained if it gets 200 (HTTP_OK) status.
Moreover cases when connection is closed, I don't get "Connection: close"
response either.
Is this an expected behavior or something is wrong here?

Thanks,
Ari Pernick [MSFT]
2008-10-07 21:50:01 UTC
Permalink
I'm going to attempt some psychic debugging and ask if you are draining any
Entity Body on the responses where keep alive isn't working.

-- Ari

This posting is provided "AS IS" with no warranties, and confers no rights
Post by Ram
Hi,
Although Connection: "Keep-Alive" header is present, my WinHttp client
drops a connetion if it gets HTTP response 404(file not found) or 304(file
not modified) and the same is maintained if it gets 200 (HTTP_OK) status.
Moreover cases when connection is closed, I don't get "Connection: close"
response either.
Is this an expected behavior or something is wrong here?
Thanks,
s***@yahoo.co.uk
2008-11-13 13:08:57 UTC
Permalink
On Oct 8, 2:50 am, Ari Pernick [MSFT]
Post by Ari Pernick [MSFT]
I'm going to attempt some psychic debugging and ask if you are draining any
Entity Body on the responses where keep alive isn't working.
-- Ari
This posting is provided "AS IS" with no warranties, and confers no rights
Hi,
 Although Connection: "Keep-Alive" header is present, my WinHttp client
drops a connetion if it gets HTTP response 404(file not found) or 304(file
not modified) and the same is maintained if it gets 200 (HTTP_OK) status.
Moreover cases when connection is closed, I don't get "Connection: close"
response either.
Is this an expected behavior or something is wrong here?
Thanks,- Hide quoted text -
- Show quoted text -
Would you please rephrase your question. I could understand it.
Sorry. :(
Ari Pernick [MSFT]
2008-11-13 16:08:07 UTC
Permalink
Do you recieve all the data from the 304/404 responses?
On Oct 8, 2:50 am, Ari Pernick [MSFT]
Post by Ari Pernick [MSFT]
I'm going to attempt some psychic debugging and ask if you are draining any
Entity Body on the responses where keep alive isn't working.
-- Ari
This posting is provided "AS IS" with no warranties, and confers no rights
Post by Ram
Hi,
Although Connection: "Keep-Alive" header is present, my WinHttp client
drops a connetion if it gets HTTP response 404(file not found) or 304(file
not modified) and the same is maintained if it gets 200 (HTTP_OK) status.
Moreover cases when connection is closed, I don't get "Connection: close"
response either.
Is this an expected behavior or something is wrong here?
Thanks,- Hide quoted text -
- Show quoted text -
Would you please rephrase your question. I could understand it.
Sorry. :(
Ram
2008-11-18 09:53:42 UTC
Permalink
On Nov 13, 9:08 pm, Ari Pernick [MSFT]
Post by Ari Pernick [MSFT]
Do you recieve all the data from the 304/404 responses?
On Oct 8, 2:50 am, Ari Pernick [MSFT]
Post by Ari Pernick [MSFT]
I'm going to attempt some psychic debugging and ask if you are draining any
Entity Body on the responses where keep alive isn't working.
-- Ari
This posting is provided "AS IS" with no warranties, and confers no rights
Hi,
 Although Connection: "Keep-Alive" header is present, my WinHttp client
drops a connetion if it gets HTTP response 404(file not found) or 304(file
not modified) and the same is maintained if it gets 200 (HTTP_OK) status.
Moreover cases when connection is closed, I don't get "Connection: close"
response either.
Is this an expected behavior or something is wrong here?
Thanks,- Hide quoted text -
- Show quoted text -
Would you please rephrase your question. I could understand it.
Sorry. :(- Hide quoted text -
- Show quoted text -
No, I immediately close the request handle if I get 304/404 return
status.

I have read somewhere that some trailing garbage data can make WinHttp
to drop the connection in cases of 304/404 response. Should I make a
call to WinHttpReadData() to read and reject the response data?
Ari Pernick [MSFT]
2008-11-18 16:21:03 UTC
Permalink
Yes, If you want a connection to have a change to get reused, regardless of
the response status code, you need to drain the response data. Most people do
this for 200's because they want the response entitiy body. 404 responses
often have entitiy body too. Sometimes the response is so short that the
buffer we used internally to catch the headers covers it all, but you should
probably drain the response anyways. I'll also point out that you might want
to avoid a DOS/bad experience from a malicious server by limiting the amount
of data you are willing to drain from the connection. You could be super
fancy and mirror winhttp when it has to drain a connection (auth/redirects)
by querying for WINHTTP_OPTION_MAX_RESPONSE_DRAIN_SIZE or just go for the
default value (1 MB IIRC).
Post by Ram
No, I immediately close the request handle if I get 304/404 return
status.
I have read somewhere that some trailing garbage data can make WinHttp
to drop the connection in cases of 304/404 response. Should I make a
call to WinHttpReadData() to read and reject the response data?
Ram
2008-11-25 07:05:00 UTC
Permalink
Thanks a lot Ari. I will give it a try.
BTW, I already have a limit on maximum amount of data, that can be
downloaded from a connection.
Post by Ari Pernick [MSFT]
Yes, If you want a connection to have a change to get reused, regardless of
the response status code, you need to drain the response data. Most people do
this for 200's because they want the response entitiy body. 404 responses
often have entitiy body too. Sometimes the response is so short that the
buffer we used internally to catch the headers covers it all, but you should
probably drain the response anyways. I'll also point out that you might want
to avoid a DOS/bad experience from a malicious server by limiting the amount
of data you are willing to drain from the connection. You could be super
fancy and mirror winhttp when it has to drain a connection (auth/redirects)
by querying for WINHTTP_OPTION_MAX_RESPONSE_DRAIN_SIZE or just go for the
default value (1 MB IIRC).
Post by Ram
No, I immediately close the request handle if I get 304/404 return
status.
I have read somewhere that some trailing garbage data can make WinHttp
to drop the connection in cases of 304/404 response. Should I make a
call to WinHttpReadData() to read and reject the response data?
Loading...