httpclient: use defines for status codes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
diff --git a/src/transports/http.c b/src/transports/http.c
index e63827c..65435d1 100644
--- a/src/transports/http.c
+++ b/src/transports/http.c
@@ -243,22 +243,23 @@ static int handle_response(
/* If we're in the middle of challenge/response auth, continue. */
if (allow_replay && response->resend_credentials) {
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)
return error;
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)
return error;
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");
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);
return -1;
}
diff --git a/src/transports/httpclient.c b/src/transports/httpclient.c
index 585f04f..b565bf5 100644
--- a/src/transports/httpclient.c
+++ b/src/transports/httpclient.c
@@ -126,11 +126,11 @@ struct git_http_client {
bool git_http_response_is_redirect(git_http_response *response)
{
- return (response->status == 301 ||
- response->status == 302 ||
- response->status == 303 ||
- response->status == 307 ||
- response->status == 308);
+ return (response->status == GIT_HTTP_MOVED_PERMANENTLY ||
+ response->status == GIT_HTTP_FOUND ||
+ response->status == GIT_HTTP_SEE_OTHER ||
+ response->status == GIT_HTTP_TEMPORARY_REDIRECT ||
+ response->status == GIT_HTTP_PERMANENT_REDIRECT);
}
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)
{
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->is_complete &&
!auth_context->is_complete(auth_context))
return 1;
- if (response->status == 407 &&
+ if (response->status == GIT_HTTP_STATUS_PROXY_AUTHENTICATION_REQUIRED &&
(auth_context = client->proxy.auth_context) &&
auth_context->is_complete &&
!auth_context->is_complete(auth_context))
@@ -914,12 +914,12 @@ static int proxy_connect(
assert(client->state == DONE);
- if (response.status == 407) {
+ if (response.status == GIT_HTTP_STATUS_PROXY_AUTHENTICATION_REQUIRED) {
save_early_response(client, &response);
error = GIT_RETRY;
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);
error = -1;
goto done;
@@ -1236,7 +1236,7 @@ int git_http_client_send_request(
error = 0;
- if (response.status != 100) {
+ if (response.status != GIT_HTTP_STATUS_CONTINUE) {
save_early_response(client, &response);
goto done;
}
diff --git a/src/transports/httpclient.h b/src/transports/httpclient.h
index cb21866..da764fd 100644
--- a/src/transports/httpclient.h
+++ b/src/transports/httpclient.h
@@ -11,6 +11,16 @@
#include "common.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;
/** Method for the HTTP request */