Search code examples
c++winapiwebsocketwininetwinhttp

Is there any example of HttpSendHttpResponse usage of the HTTP_SEND_RESPONSE_FLAG_OPAQUE flag (needed for WebSocket support)?


I am using HttpSendHttpResponse() with the HTTP_SEND_RESPONSE_FLAG_OPAQUE flag, as proposed by Microsoft (only with 101 response status and response headers prepared using the WebSocketBeginServerHandshake() function), but I receive an ERROR_INVALID_PARAMETER error.

Without this flag, I'm able to establish a WebSocket connection with my server from my browser, but as far as I know I will not be able to use this connection as a WebSocket because HTTP.SYS would try to interpret the connection traffic as HTTP-framed.

Could someone provide me with a link to a working example of HttpSendHttpResponse() usage of the HTTP_SEND_RESPONSE_FLAG_OPAQUE flag?


Solution

  • Based on the document: HttpSendHttpResponse

    HttpSendHttpResponse returns ERROR_INVALID_PARAMETER for all other HTTP response types if HTTP_SEND_RESPONSE_FLAG_OPAQUE flag is used.

    So it is expected. Just ignore this error temporarily and you can check the receiver part to see if it can receive the correct data.