wqweto / VbAsyncSocket

Sockets with pure VB6 impl of TLS encryption
MIT License
164 stars 31 forks source link

Small behavior difference between WinHTTP and VbAsyncSocket #25

Closed Montclair closed 2 years ago

Montclair commented 2 years ago

I'm rewriting an interface to a supplier's XML server. We currently test if their server is up by sending an empty payload via post. When we do this using WinHTTP, we get a "400 Bad Request" response which is what we expect. When using cHttpRequest, we get a "411 Length Required" response. It's not a big deal at all to test for either of those, but I thought you might want to know of the behavior difference. WinHTTP is probably setting the request header content-length to zero. I think the issue is here in your "Send" function, where it omits the header entirely -- but that's just a guess:

'--- prepare headers
        If Not .Stream Is Nothing Then
            SetRequestHeader HDR_CONTENT_LENGTH, IStream_GetSize(.Stream)
        End If

Not a big deal and technically what you have is probably correct, but I thought you might like to know of the difference, so as to make this as compatible as possible with existing WinHTTP behavior.

Maybe a patch to

'--- prepare headers
        If Not .Stream Is Nothing Then
            SetRequestHeader HDR_CONTENT_LENGTH, IStream_GetSize(.Stream)
        Else
            SetRequestHeader HDR_CONTENT_LENGTH, 0
        End if

EDIT: I made this patch locally and now the behavior is consistent with WinHTTP.

wqweto commented 2 years ago

It looks like WinHttpRequest client sends Content-Length header for every method which is not GET even if there is no body passed to Send call -- it just sends 0 for Content-Length.

Fixed in 13532ff07311c703502deff6309e6887188da5c2

Montclair commented 2 years ago

Tested and works. Thanks!