Fix #19094 and #21947 - Fix HTTP status conversion inconsistencies

pull/22901/head
Yash Tibrewal 5 years ago
parent 06d4be0f19
commit 376d8689d2
  1. 4
      src/core/ext/filters/http/client/http_client_filter.cc
  2. 3
      src/core/ext/transport/chttp2/transport/chttp2_transport.cc
  3. 20
      src/core/lib/transport/status_conversion.cc
  4. 45
      test/core/end2end/bad_server_response_test.cc
  5. 15
      test/core/transport/status_conversion_test.cc

@ -31,6 +31,7 @@
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/slice/slice_string_helpers.h"
#include "src/core/lib/transport/static_metadata.h"
#include "src/core/lib/transport/status_conversion.h"
#include "src/core/lib/transport/transport_impl.h"
#define EXPECTED_CONTENT_TYPE "application/grpc"
@ -120,7 +121,8 @@ static grpc_error* client_filter_incoming_metadata(grpc_metadata_batch* b) {
GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"Received http2 :status header with non-200 OK status"),
GRPC_ERROR_STR_VALUE, grpc_slice_from_copied_string(val)),
GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_CANCELLED),
GRPC_ERROR_INT_GRPC_STATUS,
grpc_http2_status_to_grpc_status(atoi(val))),
GRPC_ERROR_STR_GRPC_MESSAGE, grpc_slice_from_copied_string(msg));
gpr_free(val);
gpr_free(msg);

@ -2485,7 +2485,8 @@ static grpc_error* try_http_parsing(grpc_chttp2_transport* t) {
grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"Trying to connect an http1.x server"),
GRPC_ERROR_INT_HTTP_STATUS, response.status),
GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE);
GRPC_ERROR_INT_GRPC_STATUS,
grpc_http2_status_to_grpc_status(response.status));
}
GRPC_ERROR_UNREF(parse_error);

@ -68,29 +68,21 @@ grpc_status_code grpc_http2_status_to_grpc_status(int status) {
case 200:
return GRPC_STATUS_OK;
case 400:
return GRPC_STATUS_INVALID_ARGUMENT;
return GRPC_STATUS_INTERNAL;
case 401:
return GRPC_STATUS_UNAUTHENTICATED;
case 403:
return GRPC_STATUS_PERMISSION_DENIED;
case 404:
return GRPC_STATUS_NOT_FOUND;
case 409:
return GRPC_STATUS_ABORTED;
case 412:
return GRPC_STATUS_FAILED_PRECONDITION;
case 429:
return GRPC_STATUS_RESOURCE_EXHAUSTED;
case 499:
return GRPC_STATUS_CANCELLED;
case 500:
return GRPC_STATUS_UNKNOWN;
case 501:
return GRPC_STATUS_UNIMPLEMENTED;
case 429:
return GRPC_STATUS_UNAVAILABLE;
case 502:
return GRPC_STATUS_UNAVAILABLE;
case 503:
return GRPC_STATUS_UNAVAILABLE;
case 504:
return GRPC_STATUS_DEADLINE_EXCEEDED;
return GRPC_STATUS_UNAVAILABLE;
/* everything else is unknown */
default:
return GRPC_STATUS_UNKNOWN;

@ -41,7 +41,7 @@
#include "test/core/util/test_config.h"
#include "test/core/util/test_tcp_server.h"
#define HTTP1_RESP \
#define HTTP1_RESP_400 \
"HTTP/1.0 400 Bad Request\n" \
"Content-Type: text/html; charset=UTF-8\n" \
"Content-Length: 0\n" \
@ -309,40 +309,41 @@ int main(int argc, char** argv) {
grpc_init();
/* status defined in hpack static table */
run_test(HTTP2_RESP(204), sizeof(HTTP2_RESP(204)) - 1, GRPC_STATUS_CANCELLED,
run_test(HTTP2_RESP(204), sizeof(HTTP2_RESP(204)) - 1, GRPC_STATUS_UNKNOWN,
HTTP2_DETAIL_MSG(204));
run_test(HTTP2_RESP(206), sizeof(HTTP2_RESP(206)) - 1, GRPC_STATUS_CANCELLED,
run_test(HTTP2_RESP(206), sizeof(HTTP2_RESP(206)) - 1, GRPC_STATUS_UNKNOWN,
HTTP2_DETAIL_MSG(206));
run_test(HTTP2_RESP(304), sizeof(HTTP2_RESP(304)) - 1, GRPC_STATUS_CANCELLED,
run_test(HTTP2_RESP(304), sizeof(HTTP2_RESP(304)) - 1, GRPC_STATUS_UNKNOWN,
HTTP2_DETAIL_MSG(304));
run_test(HTTP2_RESP(400), sizeof(HTTP2_RESP(400)) - 1, GRPC_STATUS_CANCELLED,
run_test(HTTP2_RESP(400), sizeof(HTTP2_RESP(400)) - 1, GRPC_STATUS_INTERNAL,
HTTP2_DETAIL_MSG(400));
run_test(HTTP2_RESP(404), sizeof(HTTP2_RESP(404)) - 1, GRPC_STATUS_CANCELLED,
HTTP2_DETAIL_MSG(404));
run_test(HTTP2_RESP(500), sizeof(HTTP2_RESP(500)) - 1, GRPC_STATUS_CANCELLED,
run_test(HTTP2_RESP(404), sizeof(HTTP2_RESP(404)) - 1,
GRPC_STATUS_UNIMPLEMENTED, HTTP2_DETAIL_MSG(404));
run_test(HTTP2_RESP(500), sizeof(HTTP2_RESP(500)) - 1, GRPC_STATUS_UNKNOWN,
HTTP2_DETAIL_MSG(500));
/* status not defined in hpack static table */
run_test(HTTP2_RESP(401), sizeof(HTTP2_RESP(401)) - 1, GRPC_STATUS_CANCELLED,
HTTP2_DETAIL_MSG(401));
run_test(HTTP2_RESP(403), sizeof(HTTP2_RESP(403)) - 1, GRPC_STATUS_CANCELLED,
HTTP2_DETAIL_MSG(403));
run_test(HTTP2_RESP(502), sizeof(HTTP2_RESP(502)) - 1, GRPC_STATUS_CANCELLED,
HTTP2_DETAIL_MSG(502));
run_test(HTTP2_RESP(401), sizeof(HTTP2_RESP(401)) - 1,
GRPC_STATUS_UNAUTHENTICATED, HTTP2_DETAIL_MSG(401));
run_test(HTTP2_RESP(403), sizeof(HTTP2_RESP(403)) - 1,
GRPC_STATUS_PERMISSION_DENIED, HTTP2_DETAIL_MSG(403));
run_test(HTTP2_RESP(429), sizeof(HTTP2_RESP(429)) - 1,
GRPC_STATUS_UNAVAILABLE, HTTP2_DETAIL_MSG(429));
run_test(HTTP2_RESP(499), sizeof(HTTP2_RESP(499)) - 1, GRPC_STATUS_UNKNOWN,
HTTP2_DETAIL_MSG(499));
run_test(HTTP2_RESP(502), sizeof(HTTP2_RESP(502)) - 1,
GRPC_STATUS_UNAVAILABLE, HTTP2_DETAIL_MSG(502));
run_test(HTTP2_RESP(503), sizeof(HTTP2_RESP(503)) - 1,
GRPC_STATUS_UNAVAILABLE, HTTP2_DETAIL_MSG(503));
run_test(HTTP2_RESP(504), sizeof(HTTP2_RESP(504)) - 1,
GRPC_STATUS_UNAVAILABLE, HTTP2_DETAIL_MSG(504));
/* unparseable response */
run_test(UNPARSEABLE_RESP, sizeof(UNPARSEABLE_RESP) - 1, GRPC_STATUS_UNKNOWN,
nullptr);
/* http1 response */
run_test(HTTP1_RESP, sizeof(HTTP1_RESP) - 1, GRPC_STATUS_UNAVAILABLE,
run_test(HTTP1_RESP_400, sizeof(HTTP1_RESP_400) - 1, GRPC_STATUS_INTERNAL,
HTTP1_DETAIL_MSG);
grpc_shutdown();

@ -147,17 +147,18 @@ static void test_http2_error_to_grpc_status() {
static void test_http2_status_to_grpc_status() {
HTTP2_STATUS_TO_GRPC_STATUS(200, GRPC_STATUS_OK);
HTTP2_STATUS_TO_GRPC_STATUS(400, GRPC_STATUS_INVALID_ARGUMENT);
HTTP2_STATUS_TO_GRPC_STATUS(400, GRPC_STATUS_INTERNAL);
HTTP2_STATUS_TO_GRPC_STATUS(401, GRPC_STATUS_UNAUTHENTICATED);
HTTP2_STATUS_TO_GRPC_STATUS(403, GRPC_STATUS_PERMISSION_DENIED);
HTTP2_STATUS_TO_GRPC_STATUS(404, GRPC_STATUS_NOT_FOUND);
HTTP2_STATUS_TO_GRPC_STATUS(409, GRPC_STATUS_ABORTED);
HTTP2_STATUS_TO_GRPC_STATUS(412, GRPC_STATUS_FAILED_PRECONDITION);
HTTP2_STATUS_TO_GRPC_STATUS(429, GRPC_STATUS_RESOURCE_EXHAUSTED);
HTTP2_STATUS_TO_GRPC_STATUS(499, GRPC_STATUS_CANCELLED);
HTTP2_STATUS_TO_GRPC_STATUS(404, GRPC_STATUS_UNIMPLEMENTED);
HTTP2_STATUS_TO_GRPC_STATUS(409, GRPC_STATUS_UNKNOWN);
HTTP2_STATUS_TO_GRPC_STATUS(412, GRPC_STATUS_UNKNOWN);
HTTP2_STATUS_TO_GRPC_STATUS(429, GRPC_STATUS_UNAVAILABLE);
HTTP2_STATUS_TO_GRPC_STATUS(499, GRPC_STATUS_UNKNOWN);
HTTP2_STATUS_TO_GRPC_STATUS(500, GRPC_STATUS_UNKNOWN);
HTTP2_STATUS_TO_GRPC_STATUS(502, GRPC_STATUS_UNAVAILABLE);
HTTP2_STATUS_TO_GRPC_STATUS(503, GRPC_STATUS_UNAVAILABLE);
HTTP2_STATUS_TO_GRPC_STATUS(504, GRPC_STATUS_DEADLINE_EXCEEDED);
HTTP2_STATUS_TO_GRPC_STATUS(504, GRPC_STATUS_UNAVAILABLE);
}
int main(int argc, char** argv) {

Loading…
Cancel
Save