Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1 | /* |
Craig Tiller | 0605995 | 2015-02-18 08:34:56 -0800 | [diff] [blame] | 2 | * Copyright 2015, Google Inc. |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are |
| 7 | * met: |
| 8 | * |
| 9 | * * Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer. |
| 11 | * * Redistributions in binary form must reproduce the above |
| 12 | * copyright notice, this list of conditions and the following disclaimer |
| 13 | * in the documentation and/or other materials provided with the |
| 14 | * distribution. |
| 15 | * * Neither the name of Google Inc. nor the names of its |
| 16 | * contributors may be used to endorse or promote products derived from |
| 17 | * this software without specific prior written permission. |
| 18 | * |
| 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | * |
| 31 | */ |
| 32 | |
| 33 | #include "src/core/channel/http_client_filter.h" |
David Klempner | a1e8693 | 2015-01-13 18:13:59 -0800 | [diff] [blame] | 34 | #include <string.h> |
Craig Tiller | 0dc5e6c | 2015-07-10 10:07:53 -0700 | [diff] [blame] | 35 | #include <grpc/support/alloc.h> |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 36 | #include <grpc/support/log.h> |
Craig Tiller | 0dc5e6c | 2015-07-10 10:07:53 -0700 | [diff] [blame] | 37 | #include <grpc/support/string_util.h> |
| 38 | #include "src/core/support/string.h" |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 39 | |
Yang Gao | 5fd0d29 | 2015-01-26 00:19:48 -0800 | [diff] [blame] | 40 | typedef struct call_data { |
Craig Tiller | 6902ad2 | 2015-04-16 08:01:49 -0700 | [diff] [blame] | 41 | grpc_linked_mdelem method; |
| 42 | grpc_linked_mdelem scheme; |
Craig Tiller | 26b3714 | 2015-07-26 12:53:27 -0700 | [diff] [blame] | 43 | grpc_linked_mdelem authority; |
Craig Tiller | 6902ad2 | 2015-04-16 08:01:49 -0700 | [diff] [blame] | 44 | grpc_linked_mdelem te_trailers; |
| 45 | grpc_linked_mdelem content_type; |
Craig Tiller | 0dc5e6c | 2015-07-10 10:07:53 -0700 | [diff] [blame] | 46 | grpc_linked_mdelem user_agent; |
Craig Tiller | 83f88d9 | 2015-04-21 16:02:05 -0700 | [diff] [blame] | 47 | int sent_initial_metadata; |
| 48 | |
| 49 | int got_initial_metadata; |
| 50 | grpc_stream_op_buffer *recv_ops; |
Craig Tiller | 1e6facb | 2015-06-11 22:47:11 -0700 | [diff] [blame] | 51 | |
Craig Tiller | 98bf7e6 | 2015-06-24 08:47:07 -0700 | [diff] [blame] | 52 | /** Closure to call when finished with the hc_on_recv hook */ |
Craig Tiller | 3382511 | 2015-09-18 07:44:19 -0700 | [diff] [blame] | 53 | grpc_closure *on_done_recv; |
Craig Tiller | 98bf7e6 | 2015-06-24 08:47:07 -0700 | [diff] [blame] | 54 | /** Receive closures are chained: we inject this closure as the on_done_recv |
| 55 | up-call on transport_op, and remember to call our on_done_recv member |
| 56 | after handling it. */ |
Craig Tiller | 3382511 | 2015-09-18 07:44:19 -0700 | [diff] [blame] | 57 | grpc_closure hc_on_recv; |
Yang Gao | 5fd0d29 | 2015-01-26 00:19:48 -0800 | [diff] [blame] | 58 | } call_data; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 59 | |
klempner | c463f74 | 2014-12-19 13:03:35 -0800 | [diff] [blame] | 60 | typedef struct channel_data { |
| 61 | grpc_mdelem *te_trailers; |
| 62 | grpc_mdelem *method; |
| 63 | grpc_mdelem *scheme; |
| 64 | grpc_mdelem *content_type; |
Craig Tiller | 5b9efed | 2015-02-03 20:13:06 -0800 | [diff] [blame] | 65 | grpc_mdelem *status; |
Craig Tiller | 0dc5e6c | 2015-07-10 10:07:53 -0700 | [diff] [blame] | 66 | /** complete user agent mdelem */ |
| 67 | grpc_mdelem *user_agent; |
klempner | c463f74 | 2014-12-19 13:03:35 -0800 | [diff] [blame] | 68 | } channel_data; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 69 | |
Craig Tiller | d1bec03 | 2015-09-18 17:29:00 -0700 | [diff] [blame] | 70 | typedef struct { |
| 71 | grpc_call_element *elem; |
| 72 | grpc_call_list *call_list; |
Craig Tiller | 10ee274 | 2015-09-22 09:25:57 -0700 | [diff] [blame^] | 73 | } client_recv_filter_args; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 74 | |
David Garcia Quintas | 13a7112 | 2015-09-18 12:43:52 -0700 | [diff] [blame] | 75 | static grpc_mdelem *client_recv_filter(void *user_data, grpc_mdelem *md) { |
Craig Tiller | 10ee274 | 2015-09-22 09:25:57 -0700 | [diff] [blame^] | 76 | client_recv_filter_args *a = user_data; |
Craig Tiller | d1bec03 | 2015-09-18 17:29:00 -0700 | [diff] [blame] | 77 | grpc_call_element *elem = a->elem; |
Craig Tiller | 6902ad2 | 2015-04-16 08:01:49 -0700 | [diff] [blame] | 78 | channel_data *channeld = elem->channel_data; |
| 79 | if (md == channeld->status) { |
| 80 | return NULL; |
| 81 | } else if (md->key == channeld->status->key) { |
Craig Tiller | d1bec03 | 2015-09-18 17:29:00 -0700 | [diff] [blame] | 82 | grpc_call_element_send_cancel(elem, a->call_list); |
Craig Tiller | 6902ad2 | 2015-04-16 08:01:49 -0700 | [diff] [blame] | 83 | return NULL; |
David Garcia Quintas | 13a7112 | 2015-09-18 12:43:52 -0700 | [diff] [blame] | 84 | } else if (md->key == channeld->content_type->key) { |
| 85 | return NULL; |
Craig Tiller | 6902ad2 | 2015-04-16 08:01:49 -0700 | [diff] [blame] | 86 | } |
| 87 | return md; |
| 88 | } |
| 89 | |
Craig Tiller | d1bec03 | 2015-09-18 17:29:00 -0700 | [diff] [blame] | 90 | static void hc_on_recv(void *user_data, int success, |
| 91 | grpc_call_list *call_list) { |
Craig Tiller | 83f88d9 | 2015-04-21 16:02:05 -0700 | [diff] [blame] | 92 | grpc_call_element *elem = user_data; |
| 93 | call_data *calld = elem->call_data; |
Craig Tiller | 37b0044 | 2015-09-04 08:39:14 -0700 | [diff] [blame] | 94 | size_t i; |
| 95 | size_t nops = calld->recv_ops->nops; |
| 96 | grpc_stream_op *ops = calld->recv_ops->ops; |
| 97 | for (i = 0; i < nops; i++) { |
| 98 | grpc_stream_op *op = &ops[i]; |
Craig Tiller | 10ee274 | 2015-09-22 09:25:57 -0700 | [diff] [blame^] | 99 | client_recv_filter_args a; |
Craig Tiller | 37b0044 | 2015-09-04 08:39:14 -0700 | [diff] [blame] | 100 | if (op->type != GRPC_OP_METADATA) continue; |
| 101 | calld->got_initial_metadata = 1; |
Craig Tiller | d1bec03 | 2015-09-18 17:29:00 -0700 | [diff] [blame] | 102 | a.elem = elem; |
| 103 | a.call_list = call_list; |
Craig Tiller | 10ee274 | 2015-09-22 09:25:57 -0700 | [diff] [blame^] | 104 | grpc_metadata_batch_filter(&op->data.metadata, client_recv_filter, &a); |
Craig Tiller | 83f88d9 | 2015-04-21 16:02:05 -0700 | [diff] [blame] | 105 | } |
Craig Tiller | d1bec03 | 2015-09-18 17:29:00 -0700 | [diff] [blame] | 106 | calld->on_done_recv->cb(calld->on_done_recv->cb_arg, success, call_list); |
Craig Tiller | 83f88d9 | 2015-04-21 16:02:05 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Craig Tiller | d9ddc77 | 2015-07-10 13:00:05 -0700 | [diff] [blame] | 109 | static grpc_mdelem *client_strip_filter(void *user_data, grpc_mdelem *md) { |
| 110 | grpc_call_element *elem = user_data; |
| 111 | channel_data *channeld = elem->channel_data; |
| 112 | /* eat the things we'd like to set ourselves */ |
| 113 | if (md->key == channeld->method->key) return NULL; |
| 114 | if (md->key == channeld->scheme->key) return NULL; |
| 115 | if (md->key == channeld->te_trailers->key) return NULL; |
| 116 | if (md->key == channeld->content_type->key) return NULL; |
| 117 | if (md->key == channeld->user_agent->key) return NULL; |
| 118 | return md; |
| 119 | } |
| 120 | |
Craig Tiller | b7959a0 | 2015-06-25 08:50:54 -0700 | [diff] [blame] | 121 | static void hc_mutate_op(grpc_call_element *elem, |
| 122 | grpc_transport_stream_op *op) { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 123 | /* grab pointers to our data from the call element */ |
| 124 | call_data *calld = elem->call_data; |
| 125 | channel_data *channeld = elem->channel_data; |
Craig Tiller | 83f88d9 | 2015-04-21 16:02:05 -0700 | [diff] [blame] | 126 | size_t i; |
Craig Tiller | 83f88d9 | 2015-04-21 16:02:05 -0700 | [diff] [blame] | 127 | if (op->send_ops && !calld->sent_initial_metadata) { |
| 128 | size_t nops = op->send_ops->nops; |
| 129 | grpc_stream_op *ops = op->send_ops->ops; |
| 130 | for (i = 0; i < nops; i++) { |
| 131 | grpc_stream_op *op = &ops[i]; |
| 132 | if (op->type != GRPC_OP_METADATA) continue; |
| 133 | calld->sent_initial_metadata = 1; |
Craig Tiller | d9ddc77 | 2015-07-10 13:00:05 -0700 | [diff] [blame] | 134 | grpc_metadata_batch_filter(&op->data.metadata, client_strip_filter, elem); |
Craig Tiller | 6902ad2 | 2015-04-16 08:01:49 -0700 | [diff] [blame] | 135 | /* Send : prefixed headers, which have to be before any application |
Craig Tiller | 83f88d9 | 2015-04-21 16:02:05 -0700 | [diff] [blame] | 136 | layer headers. */ |
Craig Tiller | 205aee1 | 2015-04-16 14:46:41 -0700 | [diff] [blame] | 137 | grpc_metadata_batch_add_head(&op->data.metadata, &calld->method, |
Craig Tiller | 1a65a23 | 2015-07-06 10:22:32 -0700 | [diff] [blame] | 138 | GRPC_MDELEM_REF(channeld->method)); |
Craig Tiller | 205aee1 | 2015-04-16 14:46:41 -0700 | [diff] [blame] | 139 | grpc_metadata_batch_add_head(&op->data.metadata, &calld->scheme, |
Craig Tiller | 1a65a23 | 2015-07-06 10:22:32 -0700 | [diff] [blame] | 140 | GRPC_MDELEM_REF(channeld->scheme)); |
Craig Tiller | 205aee1 | 2015-04-16 14:46:41 -0700 | [diff] [blame] | 141 | grpc_metadata_batch_add_tail(&op->data.metadata, &calld->te_trailers, |
Craig Tiller | 1a65a23 | 2015-07-06 10:22:32 -0700 | [diff] [blame] | 142 | GRPC_MDELEM_REF(channeld->te_trailers)); |
Craig Tiller | 205aee1 | 2015-04-16 14:46:41 -0700 | [diff] [blame] | 143 | grpc_metadata_batch_add_tail(&op->data.metadata, &calld->content_type, |
Craig Tiller | 1a65a23 | 2015-07-06 10:22:32 -0700 | [diff] [blame] | 144 | GRPC_MDELEM_REF(channeld->content_type)); |
Craig Tiller | 0dc5e6c | 2015-07-10 10:07:53 -0700 | [diff] [blame] | 145 | grpc_metadata_batch_add_tail(&op->data.metadata, &calld->user_agent, |
| 146 | GRPC_MDELEM_REF(channeld->user_agent)); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 147 | break; |
Craig Tiller | 83f88d9 | 2015-04-21 16:02:05 -0700 | [diff] [blame] | 148 | } |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 149 | } |
Craig Tiller | 83f88d9 | 2015-04-21 16:02:05 -0700 | [diff] [blame] | 150 | |
| 151 | if (op->recv_ops && !calld->got_initial_metadata) { |
| 152 | /* substitute our callback for the higher callback */ |
| 153 | calld->recv_ops = op->recv_ops; |
| 154 | calld->on_done_recv = op->on_done_recv; |
Craig Tiller | 1e6facb | 2015-06-11 22:47:11 -0700 | [diff] [blame] | 155 | op->on_done_recv = &calld->hc_on_recv; |
Craig Tiller | 83f88d9 | 2015-04-21 16:02:05 -0700 | [diff] [blame] | 156 | } |
Craig Tiller | 50d9db5 | 2015-04-23 10:52:14 -0700 | [diff] [blame] | 157 | } |
Craig Tiller | 83f88d9 | 2015-04-21 16:02:05 -0700 | [diff] [blame] | 158 | |
Craig Tiller | 06aeea7 | 2015-04-23 10:54:45 -0700 | [diff] [blame] | 159 | static void hc_start_transport_op(grpc_call_element *elem, |
Craig Tiller | d1bec03 | 2015-09-18 17:29:00 -0700 | [diff] [blame] | 160 | grpc_transport_stream_op *op, |
| 161 | grpc_call_list *call_list) { |
Craig Tiller | 50d9db5 | 2015-04-23 10:52:14 -0700 | [diff] [blame] | 162 | GRPC_CALL_LOG_OP(GPR_INFO, elem, op); |
| 163 | hc_mutate_op(elem, op); |
Craig Tiller | d1bec03 | 2015-09-18 17:29:00 -0700 | [diff] [blame] | 164 | grpc_call_next_op(elem, op, call_list); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 165 | } |
| 166 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 167 | /* Constructor for call_data */ |
| 168 | static void init_call_elem(grpc_call_element *elem, |
Craig Tiller | 50d9db5 | 2015-04-23 10:52:14 -0700 | [diff] [blame] | 169 | const void *server_transport_data, |
Craig Tiller | dfff1b8 | 2015-09-21 14:39:57 -0700 | [diff] [blame] | 170 | grpc_transport_stream_op *initial_op, |
| 171 | grpc_call_list *call_list) { |
Craig Tiller | 83f88d9 | 2015-04-21 16:02:05 -0700 | [diff] [blame] | 172 | call_data *calld = elem->call_data; |
| 173 | calld->sent_initial_metadata = 0; |
| 174 | calld->got_initial_metadata = 0; |
Craig Tiller | 1e6facb | 2015-06-11 22:47:11 -0700 | [diff] [blame] | 175 | calld->on_done_recv = NULL; |
Craig Tiller | 3382511 | 2015-09-18 07:44:19 -0700 | [diff] [blame] | 176 | grpc_closure_init(&calld->hc_on_recv, hc_on_recv, elem); |
Craig Tiller | 50d9db5 | 2015-04-23 10:52:14 -0700 | [diff] [blame] | 177 | if (initial_op) hc_mutate_op(elem, initial_op); |
Craig Tiller | 83f88d9 | 2015-04-21 16:02:05 -0700 | [diff] [blame] | 178 | } |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 179 | |
| 180 | /* Destructor for call_data */ |
Craig Tiller | d1bec03 | 2015-09-18 17:29:00 -0700 | [diff] [blame] | 181 | static void destroy_call_elem(grpc_call_element *elem, |
| 182 | grpc_call_list *call_list) {} |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 183 | |
David Klempner | ed0cbc8 | 2015-01-14 14:46:10 -0800 | [diff] [blame] | 184 | static const char *scheme_from_args(const grpc_channel_args *args) { |
Nicolas "Pixel" Noble | 213ed91 | 2015-01-30 02:11:35 +0100 | [diff] [blame] | 185 | unsigned i; |
David Klempner | a1e8693 | 2015-01-13 18:13:59 -0800 | [diff] [blame] | 186 | if (args != NULL) { |
| 187 | for (i = 0; i < args->num_args; ++i) { |
| 188 | if (args->args[i].type == GRPC_ARG_STRING && |
David Klempner | ed0cbc8 | 2015-01-14 14:46:10 -0800 | [diff] [blame] | 189 | strcmp(args->args[i].key, GRPC_ARG_HTTP2_SCHEME) == 0) { |
David Klempner | a1e8693 | 2015-01-13 18:13:59 -0800 | [diff] [blame] | 190 | return args->args[i].value.string; |
| 191 | } |
| 192 | } |
| 193 | } |
| 194 | return "http"; |
| 195 | } |
| 196 | |
Craig Tiller | 0dc5e6c | 2015-07-10 10:07:53 -0700 | [diff] [blame] | 197 | static grpc_mdstr *user_agent_from_args(grpc_mdctx *mdctx, |
| 198 | const grpc_channel_args *args) { |
| 199 | gpr_strvec v; |
| 200 | size_t i; |
| 201 | int is_first = 1; |
| 202 | char *tmp; |
| 203 | grpc_mdstr *result; |
| 204 | |
| 205 | gpr_strvec_init(&v); |
| 206 | |
| 207 | for (i = 0; args && i < args->num_args; i++) { |
| 208 | if (0 == strcmp(args->args[i].key, GRPC_ARG_PRIMARY_USER_AGENT_STRING)) { |
| 209 | if (args->args[i].type != GRPC_ARG_STRING) { |
| 210 | gpr_log(GPR_ERROR, "Channel argument '%s' should be a string", |
| 211 | GRPC_ARG_PRIMARY_USER_AGENT_STRING); |
| 212 | } else { |
| 213 | if (!is_first) gpr_strvec_add(&v, gpr_strdup(" ")); |
| 214 | is_first = 0; |
| 215 | gpr_strvec_add(&v, gpr_strdup(args->args[i].value.string)); |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | gpr_asprintf(&tmp, "%sgrpc-c/%s (%s)", is_first ? "" : " ", |
| 221 | grpc_version_string(), GPR_PLATFORM_STRING); |
| 222 | is_first = 0; |
| 223 | gpr_strvec_add(&v, tmp); |
| 224 | |
| 225 | for (i = 0; args && i < args->num_args; i++) { |
| 226 | if (0 == strcmp(args->args[i].key, GRPC_ARG_SECONDARY_USER_AGENT_STRING)) { |
| 227 | if (args->args[i].type != GRPC_ARG_STRING) { |
| 228 | gpr_log(GPR_ERROR, "Channel argument '%s' should be a string", |
| 229 | GRPC_ARG_SECONDARY_USER_AGENT_STRING); |
| 230 | } else { |
| 231 | if (!is_first) gpr_strvec_add(&v, gpr_strdup(" ")); |
| 232 | is_first = 0; |
| 233 | gpr_strvec_add(&v, gpr_strdup(args->args[i].value.string)); |
| 234 | } |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | tmp = gpr_strvec_flatten(&v, NULL); |
| 239 | gpr_strvec_destroy(&v); |
Craig Tiller | f7e7d08 | 2015-07-23 10:52:23 -0700 | [diff] [blame] | 240 | result = grpc_mdstr_from_string(mdctx, tmp, 0); |
Craig Tiller | 0dc5e6c | 2015-07-10 10:07:53 -0700 | [diff] [blame] | 241 | gpr_free(tmp); |
| 242 | |
| 243 | return result; |
| 244 | } |
| 245 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 246 | /* Constructor for channel_data */ |
Craig Tiller | 079a11b | 2015-06-30 10:07:15 -0700 | [diff] [blame] | 247 | static void init_channel_elem(grpc_channel_element *elem, grpc_channel *master, |
Craig Tiller | 5666a20 | 2015-07-31 17:25:22 -0700 | [diff] [blame] | 248 | const grpc_channel_args *channel_args, |
Craig Tiller | d1bec03 | 2015-09-18 17:29:00 -0700 | [diff] [blame] | 249 | grpc_mdctx *mdctx, int is_first, int is_last, |
| 250 | grpc_call_list *call_list) { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 251 | /* grab pointers to our data from the channel element */ |
| 252 | channel_data *channeld = elem->channel_data; |
| 253 | |
| 254 | /* The first and the last filters tend to be implemented differently to |
| 255 | handle the case that there's no 'next' filter to call on the up or down |
| 256 | path */ |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 257 | GPR_ASSERT(!is_last); |
| 258 | |
| 259 | /* initialize members */ |
| 260 | channeld->te_trailers = grpc_mdelem_from_strings(mdctx, "te", "trailers"); |
klempner | c463f74 | 2014-12-19 13:03:35 -0800 | [diff] [blame] | 261 | channeld->method = grpc_mdelem_from_strings(mdctx, ":method", "POST"); |
Craig Tiller | 5666a20 | 2015-07-31 17:25:22 -0700 | [diff] [blame] | 262 | channeld->scheme = grpc_mdelem_from_strings(mdctx, ":scheme", |
| 263 | scheme_from_args(channel_args)); |
klempner | c463f74 | 2014-12-19 13:03:35 -0800 | [diff] [blame] | 264 | channeld->content_type = |
| 265 | grpc_mdelem_from_strings(mdctx, "content-type", "application/grpc"); |
Craig Tiller | 5b9efed | 2015-02-03 20:13:06 -0800 | [diff] [blame] | 266 | channeld->status = grpc_mdelem_from_strings(mdctx, ":status", "200"); |
Craig Tiller | 0dc5e6c | 2015-07-10 10:07:53 -0700 | [diff] [blame] | 267 | channeld->user_agent = grpc_mdelem_from_metadata_strings( |
Craig Tiller | f7e7d08 | 2015-07-23 10:52:23 -0700 | [diff] [blame] | 268 | mdctx, grpc_mdstr_from_string(mdctx, "user-agent", 0), |
Craig Tiller | 26b3714 | 2015-07-26 12:53:27 -0700 | [diff] [blame] | 269 | user_agent_from_args(mdctx, channel_args)); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | /* Destructor for channel data */ |
Craig Tiller | d1bec03 | 2015-09-18 17:29:00 -0700 | [diff] [blame] | 273 | static void destroy_channel_elem(grpc_channel_element *elem, |
| 274 | grpc_call_list *call_list) { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 275 | /* grab pointers to our data from the channel element */ |
| 276 | channel_data *channeld = elem->channel_data; |
| 277 | |
Craig Tiller | 1a65a23 | 2015-07-06 10:22:32 -0700 | [diff] [blame] | 278 | GRPC_MDELEM_UNREF(channeld->te_trailers); |
| 279 | GRPC_MDELEM_UNREF(channeld->method); |
| 280 | GRPC_MDELEM_UNREF(channeld->scheme); |
| 281 | GRPC_MDELEM_UNREF(channeld->content_type); |
| 282 | GRPC_MDELEM_UNREF(channeld->status); |
Craig Tiller | 0dc5e6c | 2015-07-10 10:07:53 -0700 | [diff] [blame] | 283 | GRPC_MDELEM_UNREF(channeld->user_agent); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | const grpc_channel_filter grpc_http_client_filter = { |
Craig Tiller | e039f03 | 2015-06-25 12:54:23 -0700 | [diff] [blame] | 287 | hc_start_transport_op, grpc_channel_next_op, sizeof(call_data), |
| 288 | init_call_elem, destroy_call_elem, sizeof(channel_data), |
Craig Tiller | 1b22b9d | 2015-07-20 13:42:22 -0700 | [diff] [blame] | 289 | init_channel_elem, destroy_channel_elem, grpc_call_next_get_peer, |
| 290 | "http-client"}; |