Commit 539e62935552c59a3f51b225c67dab5d3e02debd

Edward Thomson 2019-03-22T19:06:46

http: teach auth mechanisms about connection affinity Instead of using `is_complete` to decide whether we have connection or request affinity for authentication mechanisms, set a boolean on the mechanism definition itself.

diff --git a/src/transports/auth.c b/src/transports/auth.c
index c2e2713..773e302 100644
--- a/src/transports/auth.c
+++ b/src/transports/auth.c
@@ -48,6 +48,7 @@ on_error:
 static git_http_auth_context basic_context = {
 	GIT_AUTHTYPE_BASIC,
 	GIT_CREDTYPE_USERPASS_PLAINTEXT,
+	0,
 	NULL,
 	basic_next_token,
 	NULL,
diff --git a/src/transports/auth.h b/src/transports/auth.h
index 0a80d1c..aeea6ce 100644
--- a/src/transports/auth.h
+++ b/src/transports/auth.h
@@ -28,6 +28,9 @@ struct git_http_auth_context {
 	/** Supported credentials */
 	git_credtype_t credtypes;
 
+	/** Connection affinity or request affinity */
+	unsigned connection_affinity : 1;
+
 	/** Sets the challenge on the authentication context */
 	int (*set_challenge)(git_http_auth_context *ctx, const char *challenge);
 
diff --git a/src/transports/auth_negotiate.c b/src/transports/auth_negotiate.c
index 0b6f50e..f0f2b08 100644
--- a/src/transports/auth_negotiate.c
+++ b/src/transports/auth_negotiate.c
@@ -271,6 +271,7 @@ int git_http_auth_negotiate(
 
 	ctx->parent.type = GIT_AUTHTYPE_NEGOTIATE;
 	ctx->parent.credtypes = GIT_CREDTYPE_DEFAULT;
+	ctx->parent.connection_affinity = 1;
 	ctx->parent.set_challenge = negotiate_set_challenge;
 	ctx->parent.next_token = negotiate_next_token;
 	ctx->parent.is_complete = negotiate_is_complete;
diff --git a/src/transports/auth_ntlm.c b/src/transports/auth_ntlm.c
index 9f709e2..eff09bd 100644
--- a/src/transports/auth_ntlm.c
+++ b/src/transports/auth_ntlm.c
@@ -208,6 +208,7 @@ int git_http_auth_ntlm(
 
 	ctx->parent.type = GIT_AUTHTYPE_NTLM;
 	ctx->parent.credtypes = GIT_CREDTYPE_USERPASS_PLAINTEXT;
+	ctx->parent.connection_affinity = 1;
 	ctx->parent.set_challenge = ntlm_set_challenge;
 	ctx->parent.next_token = ntlm_next_token;
 	ctx->parent.is_complete = ntlm_is_complete;
diff --git a/src/transports/http.c b/src/transports/http.c
index 3ee7af7..8e0af1b 100644
--- a/src/transports/http.c
+++ b/src/transports/http.c
@@ -1014,7 +1014,7 @@ static void reset_auth_connection(http_server *server)
 
 	if (server->authenticated &&
 	    server->auth_context &&
-	    server->auth_context->is_complete) {
+	    server->auth_context->connection_affinity) {
 		free_auth_context(server);
 
 		server->url_cred_presented = 0;