libgit2/libgit2 — pull request #2529 by chescock (2014-08-19 19:20:33+00:00)
Title: Resend POST requests for Kerberos in WinHTTP

I'm trying to use LibGit2Sharp to connect to an Apache server that uses mod_auth_kerb for authentication, and I'm getting the error "Failed to receive response: The request must be resent". It seems that the way WinHttp handles Kerberos authentication involves sending the request twice, which works fine for GET requests that have no body but fails for POST requests because it doesn’t store a copy of the request body to resend.

The workaround I’m using here is to send an initial empty POST when using Negotiate, which should trigger the 401 early and allow the actual request to succeed without having to write the body twice. I think this may be unnecessary in some cases, but I don’t see a way to tell whether it’s required and the extra empty POST appears to be harmless if it succeeds.

I’m fairly new to both Kerberos and WinHttp, so I apologize in advance if I’ve done something completely crazy and I welcome suggestions for other solutions to my problem.