Add http2 status code in error_message if it's not 200

pull/6893/head
Yuchen Zeng 9 years ago
parent a47acad040
commit ec066b3d32
  1. 2
      src/core/ext/transport/chttp2/transport/chttp2_transport.c
  2. 11
      src/core/lib/channel/channel_stack.c
  3. 5
      src/core/lib/channel/channel_stack.h
  4. 8
      src/core/lib/channel/http_client_filter.c
  5. 30
      src/core/lib/transport/transport.c
  6. 5
      src/core/lib/transport/transport.h

@ -943,7 +943,7 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx,
if (op->cancel_with_status != GRPC_STATUS_OK) {
cancel_from_api(exec_ctx, transport_global, stream_global,
op->cancel_with_status, op->optional_close_message);
op->cancel_with_status, op->optional_cancel_message);
}
if (op->close_with_status != GRPC_STATUS_OK) {

@ -266,3 +266,14 @@ void grpc_call_element_send_cancel(grpc_exec_ctx *exec_ctx,
op.cancel_with_status = GRPC_STATUS_CANCELLED;
grpc_call_next_op(exec_ctx, cur_elem, &op);
}
void grpc_call_element_send_cancel_with_message(grpc_exec_ctx *exec_ctx,
grpc_call_element *cur_elem,
grpc_status_code status,
gpr_slice *optional_message) {
grpc_transport_stream_op op;
memset(&op, 0, sizeof(op));
grpc_transport_stream_op_add_cancellation_with_message(&op, status,
optional_message);
grpc_call_next_op(exec_ctx, cur_elem, &op);
}

@ -273,6 +273,11 @@ void grpc_call_log_op(char *file, int line, gpr_log_severity severity,
void grpc_call_element_send_cancel(grpc_exec_ctx *exec_ctx,
grpc_call_element *cur_elem);
void grpc_call_element_send_cancel_with_message(grpc_exec_ctx *exec_ctx,
grpc_call_element *cur_elem,
grpc_status_code status,
gpr_slice *optional_message);
extern int grpc_trace_channel;
#define GRPC_CALL_LOG_OP(sev, elem, op) \

@ -76,7 +76,13 @@ static grpc_mdelem *client_recv_filter(void *user_data, grpc_mdelem *md) {
if (md == GRPC_MDELEM_STATUS_200) {
return NULL;
} else if (md->key == GRPC_MDSTR_STATUS) {
grpc_call_element_send_cancel(a->exec_ctx, a->elem);
char *message_string;
gpr_asprintf(&message_string, "Received http2 header with status: %s",
grpc_mdstr_as_c_string(md->value));
gpr_slice message = gpr_slice_from_copied_string(message_string);
gpr_free(message_string);
grpc_call_element_send_cancel_with_message(a->exec_ctx, a->elem,
GRPC_STATUS_CANCELLED, &message);
return NULL;
} else if (md == GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC) {
return NULL;

@ -164,6 +164,7 @@ void grpc_transport_stream_op_add_cancellation(grpc_transport_stream_op *op,
GPR_ASSERT(status != GRPC_STATUS_OK);
if (op->cancel_with_status == GRPC_STATUS_OK) {
op->cancel_with_status = status;
op->optional_cancel_message = NULL;
}
if (op->close_with_status != GRPC_STATUS_OK) {
op->close_with_status = GRPC_STATUS_OK;
@ -189,6 +190,35 @@ static void free_message(grpc_exec_ctx *exec_ctx, void *p, bool iomgr_success) {
gpr_free(cmd);
}
void grpc_transport_stream_op_add_cancellation_with_message(
grpc_transport_stream_op *op, grpc_status_code status,
gpr_slice *optional_message) {
close_message_data *cmd;
GPR_ASSERT(status != GRPC_STATUS_OK);
if (op->cancel_with_status != GRPC_STATUS_OK) {
if (optional_message) {
gpr_slice_unref(*optional_message);
}
return;
}
if (optional_message) {
cmd = gpr_malloc(sizeof(*cmd));
cmd->message = *optional_message;
cmd->then_call = op->on_complete;
grpc_closure_init(&cmd->closure, free_message, cmd);
op->on_complete = &cmd->closure;
op->optional_cancel_message = &cmd->message;
}
op->cancel_with_status = status;
if (op->close_with_status != GRPC_STATUS_OK) {
op->close_with_status = GRPC_STATUS_OK;
if (op->optional_close_message != NULL) {
gpr_slice_unref(*op->optional_close_message);
op->optional_close_message = NULL;
}
}
}
void grpc_transport_stream_op_add_close(grpc_transport_stream_op *op,
grpc_status_code status,
gpr_slice *optional_message) {

@ -137,6 +137,7 @@ typedef struct grpc_transport_stream_op {
/** If != GRPC_STATUS_OK, cancel this stream */
grpc_status_code cancel_with_status;
gpr_slice *optional_cancel_message;
/** If != GRPC_STATUS_OK, send grpc-status, grpc-message, and close this
stream for both reading and writing */
@ -221,6 +222,10 @@ void grpc_transport_stream_op_finish_with_failure(grpc_exec_ctx *exec_ctx,
void grpc_transport_stream_op_add_cancellation(grpc_transport_stream_op *op,
grpc_status_code status);
void grpc_transport_stream_op_add_cancellation_with_message(
grpc_transport_stream_op *op, grpc_status_code status,
gpr_slice *optional_message);
void grpc_transport_stream_op_add_close(grpc_transport_stream_op *op,
grpc_status_code status,
gpr_slice *optional_message);

Loading…
Cancel
Save