Commit 29762e40 by Edward Thomson

httpclient: use defines for status codes

parent 3e9ee04f
...@@ -243,22 +243,23 @@ static int handle_response( ...@@ -243,22 +243,23 @@ static int handle_response(
/* If we're in the middle of challenge/response auth, continue. */ /* If we're in the middle of challenge/response auth, continue. */
if (allow_replay && response->resend_credentials) { if (allow_replay && response->resend_credentials) {
return 0; return 0;
} else if (allow_replay && response->status == 401) { } else if (allow_replay && response->status == GIT_HTTP_STATUS_UNAUTHORIZED) {
if ((error = handle_remote_auth(stream, response)) < 0) if ((error = handle_remote_auth(stream, response)) < 0)
return error; return error;
return git_http_client_skip_body(transport->http_client); return git_http_client_skip_body(transport->http_client);
} else if (allow_replay && response->status == 407) { } else if (allow_replay && response->status == GIT_HTTP_STATUS_PROXY_AUTHENTICATION_REQUIRED) {
if ((error = handle_proxy_auth(stream, response)) < 0) if ((error = handle_proxy_auth(stream, response)) < 0)
return error; return error;
return git_http_client_skip_body(transport->http_client); return git_http_client_skip_body(transport->http_client);
} else if (response->status == 401 || response->status == 407) { } else if (response->status == GIT_HTTP_STATUS_UNAUTHORIZED ||
response->status == GIT_HTTP_STATUS_PROXY_AUTHENTICATION_REQUIRED) {
git_error_set(GIT_ERROR_NET, "unexpected authentication failure"); git_error_set(GIT_ERROR_NET, "unexpected authentication failure");
return -1; return -1;
} }
if (response->status != 200) { if (response->status != GIT_HTTP_STATUS_OK) {
git_error_set(GIT_ERROR_NET, "unexpected http status code: %d", response->status); git_error_set(GIT_ERROR_NET, "unexpected http status code: %d", response->status);
return -1; return -1;
} }
......
...@@ -126,11 +126,11 @@ struct git_http_client { ...@@ -126,11 +126,11 @@ struct git_http_client {
bool git_http_response_is_redirect(git_http_response *response) bool git_http_response_is_redirect(git_http_response *response)
{ {
return (response->status == 301 || return (response->status == GIT_HTTP_MOVED_PERMANENTLY ||
response->status == 302 || response->status == GIT_HTTP_FOUND ||
response->status == 303 || response->status == GIT_HTTP_SEE_OTHER ||
response->status == 307 || response->status == GIT_HTTP_TEMPORARY_REDIRECT ||
response->status == 308); response->status == GIT_HTTP_PERMANENT_REDIRECT);
} }
void git_http_response_dispose(git_http_response *response) void git_http_response_dispose(git_http_response *response)
...@@ -316,13 +316,13 @@ static int resend_needed(git_http_client *client, git_http_response *response) ...@@ -316,13 +316,13 @@ static int resend_needed(git_http_client *client, git_http_response *response)
{ {
git_http_auth_context *auth_context; git_http_auth_context *auth_context;
if (response->status == 401 && if (response->status == GIT_HTTP_STATUS_UNAUTHORIZED &&
(auth_context = client->server.auth_context) && (auth_context = client->server.auth_context) &&
auth_context->is_complete && auth_context->is_complete &&
!auth_context->is_complete(auth_context)) !auth_context->is_complete(auth_context))
return 1; return 1;
if (response->status == 407 && if (response->status == GIT_HTTP_STATUS_PROXY_AUTHENTICATION_REQUIRED &&
(auth_context = client->proxy.auth_context) && (auth_context = client->proxy.auth_context) &&
auth_context->is_complete && auth_context->is_complete &&
!auth_context->is_complete(auth_context)) !auth_context->is_complete(auth_context))
...@@ -914,12 +914,12 @@ static int proxy_connect( ...@@ -914,12 +914,12 @@ static int proxy_connect(
assert(client->state == DONE); assert(client->state == DONE);
if (response.status == 407) { if (response.status == GIT_HTTP_STATUS_PROXY_AUTHENTICATION_REQUIRED) {
save_early_response(client, &response); save_early_response(client, &response);
error = GIT_RETRY; error = GIT_RETRY;
goto done; goto done;
} else if (response.status != 200) { } else if (response.status != GIT_HTTP_STATUS_OK) {
git_error_set(GIT_ERROR_NET, "proxy returned unexpected status: %d", response.status); git_error_set(GIT_ERROR_NET, "proxy returned unexpected status: %d", response.status);
error = -1; error = -1;
goto done; goto done;
...@@ -1236,7 +1236,7 @@ int git_http_client_send_request( ...@@ -1236,7 +1236,7 @@ int git_http_client_send_request(
error = 0; error = 0;
if (response.status != 100) { if (response.status != GIT_HTTP_STATUS_CONTINUE) {
save_early_response(client, &response); save_early_response(client, &response);
goto done; goto done;
} }
......
...@@ -11,6 +11,16 @@ ...@@ -11,6 +11,16 @@
#include "common.h" #include "common.h"
#include "net.h" #include "net.h"
#define GIT_HTTP_STATUS_CONTINUE 100
#define GIT_HTTP_STATUS_OK 200
#define GIT_HTTP_MOVED_PERMANENTLY 301
#define GIT_HTTP_FOUND 302
#define GIT_HTTP_SEE_OTHER 303
#define GIT_HTTP_TEMPORARY_REDIRECT 307
#define GIT_HTTP_PERMANENT_REDIRECT 308
#define GIT_HTTP_STATUS_UNAUTHORIZED 401
#define GIT_HTTP_STATUS_PROXY_AUTHENTICATION_REQUIRED 407
typedef struct git_http_client git_http_client; typedef struct git_http_client git_http_client;
/** Method for the HTTP request */ /** Method for the HTTP request */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment