blob: 26baae1eabac443cd9e916f6b69f44b5ff7092ee [file] [log] [blame]
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001/*
2 *
Craig Tiller6169d5f2016-03-31 07:46:18 -07003 * Copyright 2015, Google Inc.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08004 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
Craig Tiller9533d042016-03-25 17:11:06 -070034#include "src/core/lib/http/httpcli.h"
35#include "src/core/lib/iomgr/sockaddr.h"
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080036
37#include <string.h>
38
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080039#include <grpc/support/alloc.h>
40#include <grpc/support/log.h>
Masood Malekghassemi701af602015-06-03 15:01:17 -070041#include <grpc/support/string_util.h>
Craig Tiller6a64bfd2016-05-09 13:05:03 -070042#include <grpc/support/useful.h>
Craig Tiller1d7704d2016-02-25 14:07:29 -080043
Craig Tiller9533d042016-03-25 17:11:06 -070044#include "src/core/lib/http/format_request.h"
45#include "src/core/lib/http/parser.h"
46#include "src/core/lib/iomgr/endpoint.h"
47#include "src/core/lib/iomgr/iomgr_internal.h"
48#include "src/core/lib/iomgr/resolve_address.h"
Craig Tiller6a64bfd2016-05-09 13:05:03 -070049#include "src/core/lib/iomgr/sockaddr_utils.h"
Craig Tiller9533d042016-03-25 17:11:06 -070050#include "src/core/lib/iomgr/tcp_client.h"
51#include "src/core/lib/support/string.h"
Craig Tiller69b093b2016-02-25 19:04:07 -080052
Craig Tillera82950e2015-09-22 12:33:20 -070053typedef struct {
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080054 gpr_slice request_text;
Matthew Iselin1824f052016-02-10 12:16:06 +110055 grpc_http_parser parser;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080056 grpc_resolved_addresses *addresses;
57 size_t next_address;
58 grpc_endpoint *ep;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080059 char *host;
Craig Tillercc0535d2015-12-08 15:14:47 -080060 char *ssl_host_override;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080061 gpr_timespec deadline;
62 int have_read_byte;
Craig Tillerf53d9c82015-08-04 14:19:43 -070063 const grpc_httpcli_handshaker *handshaker;
Craig Tiller5b15afd2016-05-04 15:00:14 -070064 grpc_closure *on_done;
Craig Tillera0abe372015-06-01 11:31:08 -070065 grpc_httpcli_context *context;
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -070066 grpc_polling_entity *pollent;
Craig Tillerf39f2d62015-06-06 14:43:06 -070067 grpc_iomgr_object iomgr_obj;
Craig Tillerb0298592015-08-27 07:38:01 -070068 gpr_slice_buffer incoming;
69 gpr_slice_buffer outgoing;
Craig Tiller33825112015-09-18 07:44:19 -070070 grpc_closure on_read;
71 grpc_closure done_write;
Craig Tillerd1bec032015-09-18 17:29:00 -070072 grpc_closure connected;
Craig Tiller6a64bfd2016-05-09 13:05:03 -070073 grpc_error *overall_error;
Craig Tiller20afa3d2016-10-17 14:52:14 -070074 grpc_resource_quota *resource_quota;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080075} internal_request;
76
ctiller40260c42014-12-17 17:03:15 -080077static grpc_httpcli_get_override g_get_override = NULL;
78static grpc_httpcli_post_override g_post_override = NULL;
79
Craig Tillera82950e2015-09-22 12:33:20 -070080static void plaintext_handshake(grpc_exec_ctx *exec_ctx, void *arg,
81 grpc_endpoint *endpoint, const char *host,
Craig Tiller449c64b2016-06-13 16:26:50 -070082 gpr_timespec deadline,
Craig Tillera82950e2015-09-22 12:33:20 -070083 void (*on_done)(grpc_exec_ctx *exec_ctx,
84 void *arg,
85 grpc_endpoint *endpoint)) {
86 on_done(exec_ctx, arg, endpoint);
Craig Tillerf53d9c82015-08-04 14:19:43 -070087}
88
Craig Tillera82950e2015-09-22 12:33:20 -070089const grpc_httpcli_handshaker grpc_httpcli_plaintext = {"http",
90 plaintext_handshake};
Craig Tillerf53d9c82015-08-04 14:19:43 -070091
Craig Tillera82950e2015-09-22 12:33:20 -070092void grpc_httpcli_context_init(grpc_httpcli_context *context) {
Craig Tiller69b093b2016-02-25 19:04:07 -080093 context->pollset_set = grpc_pollset_set_create();
Craig Tillera0abe372015-06-01 11:31:08 -070094}
95
Craig Tillera82950e2015-09-22 12:33:20 -070096void grpc_httpcli_context_destroy(grpc_httpcli_context *context) {
Craig Tiller69b093b2016-02-25 19:04:07 -080097 grpc_pollset_set_destroy(context->pollset_set);
Craig Tillera0abe372015-06-01 11:31:08 -070098}
99
Craig Tiller6a64bfd2016-05-09 13:05:03 -0700100static void next_address(grpc_exec_ctx *exec_ctx, internal_request *req,
101 grpc_error *due_to_error);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800102
Craig Tillera82950e2015-09-22 12:33:20 -0700103static void finish(grpc_exec_ctx *exec_ctx, internal_request *req,
Craig Tiller5b15afd2016-05-04 15:00:14 -0700104 grpc_error *error) {
David Garcia Quintasc4d51122016-06-06 14:56:02 -0700105 grpc_polling_entity_del_from_pollset_set(exec_ctx, req->pollent,
David Garcia Quintas69ff63d2016-06-06 16:39:47 -0700106 req->context->pollset_set);
Craig Tiller332f1b32016-05-24 13:21:21 -0700107 grpc_exec_ctx_sched(exec_ctx, req->on_done, error, NULL);
Matthew Iselin1824f052016-02-10 12:16:06 +1100108 grpc_http_parser_destroy(&req->parser);
Craig Tillera82950e2015-09-22 12:33:20 -0700109 if (req->addresses != NULL) {
110 grpc_resolved_addresses_destroy(req->addresses);
111 }
112 if (req->ep != NULL) {
113 grpc_endpoint_destroy(exec_ctx, req->ep);
114 }
115 gpr_slice_unref(req->request_text);
116 gpr_free(req->host);
Craig Tillercc0535d2015-12-08 15:14:47 -0800117 gpr_free(req->ssl_host_override);
Craig Tillera82950e2015-09-22 12:33:20 -0700118 grpc_iomgr_unregister_object(&req->iomgr_obj);
119 gpr_slice_buffer_destroy(&req->incoming);
120 gpr_slice_buffer_destroy(&req->outgoing);
Craig Tiller6a64bfd2016-05-09 13:05:03 -0700121 GRPC_ERROR_UNREF(req->overall_error);
Craig Tiller20afa3d2016-10-17 14:52:14 -0700122 grpc_resource_quota_internal_unref(exec_ctx, req->resource_quota);
Craig Tillera82950e2015-09-22 12:33:20 -0700123 gpr_free(req);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800124}
125
Craig Tiller6a64bfd2016-05-09 13:05:03 -0700126static void append_error(internal_request *req, grpc_error *error) {
127 if (req->overall_error == GRPC_ERROR_NONE) {
128 req->overall_error = GRPC_ERROR_CREATE("Failed HTTP/1 client request");
129 }
130 grpc_resolved_address *addr = &req->addresses->addrs[req->next_address - 1];
131 char *addr_text = grpc_sockaddr_to_uri((struct sockaddr *)addr->addr);
132 req->overall_error = grpc_error_add_child(
133 req->overall_error,
134 grpc_error_set_str(error, GRPC_ERROR_STR_TARGET_ADDRESS, addr_text));
135 gpr_free(addr_text);
136}
137
Craig Tillera82950e2015-09-22 12:33:20 -0700138static void do_read(grpc_exec_ctx *exec_ctx, internal_request *req) {
139 grpc_endpoint_read(exec_ctx, req->ep, &req->incoming, &req->on_read);
Craig Tillerb0298592015-08-27 07:38:01 -0700140}
141
Craig Tillerc027e772016-05-03 16:27:00 -0700142static void on_read(grpc_exec_ctx *exec_ctx, void *user_data,
143 grpc_error *error) {
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800144 internal_request *req = user_data;
145 size_t i;
146
Craig Tillere6deeb12016-05-09 13:14:32 -0700147 for (i = 0; i < req->incoming.count; i++) {
Craig Tillera82950e2015-09-22 12:33:20 -0700148 if (GPR_SLICE_LENGTH(req->incoming.slices[i])) {
149 req->have_read_byte = 1;
Craig Tillere6deeb12016-05-09 13:14:32 -0700150 grpc_error *err =
Mark D. Roth714c7ec2016-08-04 12:58:16 -0700151 grpc_http_parser_parse(&req->parser, req->incoming.slices[i], NULL);
Craig Tillere6deeb12016-05-09 13:14:32 -0700152 if (err != GRPC_ERROR_NONE) {
153 finish(exec_ctx, req, err);
154 return;
155 }
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800156 }
Craig Tillera82950e2015-09-22 12:33:20 -0700157 }
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800158
Craig Tillerc027e772016-05-03 16:27:00 -0700159 if (error == GRPC_ERROR_NONE) {
Craig Tillera82950e2015-09-22 12:33:20 -0700160 do_read(exec_ctx, req);
161 } else if (!req->have_read_byte) {
Craig Tiller6a64bfd2016-05-09 13:05:03 -0700162 next_address(exec_ctx, req, GRPC_ERROR_REF(error));
Craig Tillera82950e2015-09-22 12:33:20 -0700163 } else {
Craig Tillere6deeb12016-05-09 13:14:32 -0700164 finish(exec_ctx, req, grpc_http_parser_eof(&req->parser));
Craig Tillera82950e2015-09-22 12:33:20 -0700165 }
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800166}
167
Craig Tillera82950e2015-09-22 12:33:20 -0700168static void on_written(grpc_exec_ctx *exec_ctx, internal_request *req) {
169 do_read(exec_ctx, req);
Craig Tillerd1bec032015-09-18 17:29:00 -0700170}
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800171
Craig Tillerc027e772016-05-03 16:27:00 -0700172static void done_write(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800173 internal_request *req = arg;
Craig Tillerc027e772016-05-03 16:27:00 -0700174 if (error == GRPC_ERROR_NONE) {
Craig Tillera82950e2015-09-22 12:33:20 -0700175 on_written(exec_ctx, req);
176 } else {
Craig Tiller6a64bfd2016-05-09 13:05:03 -0700177 next_address(exec_ctx, req, GRPC_ERROR_REF(error));
Craig Tillera82950e2015-09-22 12:33:20 -0700178 }
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800179}
180
Craig Tillera82950e2015-09-22 12:33:20 -0700181static void start_write(grpc_exec_ctx *exec_ctx, internal_request *req) {
182 gpr_slice_ref(req->request_text);
183 gpr_slice_buffer_add(&req->outgoing, req->request_text);
184 grpc_endpoint_write(exec_ctx, req->ep, &req->outgoing, &req->done_write);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800185}
186
Craig Tillera82950e2015-09-22 12:33:20 -0700187static void on_handshake_done(grpc_exec_ctx *exec_ctx, void *arg,
188 grpc_endpoint *ep) {
Craig Tillerf53d9c82015-08-04 14:19:43 -0700189 internal_request *req = arg;
190
Craig Tillera82950e2015-09-22 12:33:20 -0700191 if (!ep) {
Craig Tiller6a64bfd2016-05-09 13:05:03 -0700192 next_address(exec_ctx, req,
193 GRPC_ERROR_CREATE("Unexplained handshake failure"));
Craig Tillera82950e2015-09-22 12:33:20 -0700194 return;
195 }
Craig Tillerf53d9c82015-08-04 14:19:43 -0700196
197 req->ep = ep;
Craig Tillera82950e2015-09-22 12:33:20 -0700198 start_write(exec_ctx, req);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800199}
200
Craig Tillerc027e772016-05-03 16:27:00 -0700201static void on_connected(grpc_exec_ctx *exec_ctx, void *arg,
202 grpc_error *error) {
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800203 internal_request *req = arg;
204
Craig Tillera82950e2015-09-22 12:33:20 -0700205 if (!req->ep) {
Craig Tiller6a64bfd2016-05-09 13:05:03 -0700206 next_address(exec_ctx, req, GRPC_ERROR_REF(error));
Craig Tillera82950e2015-09-22 12:33:20 -0700207 return;
208 }
Craig Tillercc0535d2015-12-08 15:14:47 -0800209 req->handshaker->handshake(
210 exec_ctx, req, req->ep,
211 req->ssl_host_override ? req->ssl_host_override : req->host,
Craig Tiller449c64b2016-06-13 16:26:50 -0700212 req->deadline, on_handshake_done);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800213}
214
Craig Tiller6a64bfd2016-05-09 13:05:03 -0700215static void next_address(grpc_exec_ctx *exec_ctx, internal_request *req,
216 grpc_error *error) {
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800217 grpc_resolved_address *addr;
Craig Tiller6a64bfd2016-05-09 13:05:03 -0700218 if (error != GRPC_ERROR_NONE) {
219 append_error(req, error);
220 }
Craig Tillera82950e2015-09-22 12:33:20 -0700221 if (req->next_address == req->addresses->naddrs) {
Craig Tiller6a64bfd2016-05-09 13:05:03 -0700222 finish(exec_ctx, req,
223 GRPC_ERROR_CREATE_REFERENCING("Failed HTTP requests to all targets",
224 &req->overall_error, 1));
Craig Tillera82950e2015-09-22 12:33:20 -0700225 return;
226 }
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800227 addr = &req->addresses->addrs[req->next_address++];
Craig Tillera82950e2015-09-22 12:33:20 -0700228 grpc_closure_init(&req->connected, on_connected, req);
Craig Tiller86958762016-09-23 12:05:34 -0700229 grpc_arg arg;
Craig Tiller153eaa72016-10-21 13:52:36 -0700230 arg.key = GRPC_ARG_RESOURCE_QUOTA;
Craig Tiller86958762016-09-23 12:05:34 -0700231 arg.type = GRPC_ARG_POINTER;
Craig Tiller20afa3d2016-10-17 14:52:14 -0700232 arg.value.pointer.p = req->resource_quota;
233 arg.value.pointer.vtable = grpc_resource_quota_arg_vtable();
Craig Tiller86958762016-09-23 12:05:34 -0700234 grpc_channel_args args = {1, &arg};
235 grpc_tcp_client_connect(
236 exec_ctx, &req->connected, &req->ep, req->context->pollset_set, &args,
237 (struct sockaddr *)&addr->addr, addr->len, req->deadline);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800238}
239
Craig Tiller5b15afd2016-05-04 15:00:14 -0700240static void on_resolved(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800241 internal_request *req = arg;
Craig Tiller5b15afd2016-05-04 15:00:14 -0700242 if (error != GRPC_ERROR_NONE) {
243 finish(exec_ctx, req, error);
Craig Tillera82950e2015-09-22 12:33:20 -0700244 return;
245 }
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800246 req->next_address = 0;
Craig Tiller6a64bfd2016-05-09 13:05:03 -0700247 next_address(exec_ctx, req, GRPC_ERROR_NONE);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800248}
249
Craig Tiller5b15afd2016-05-04 15:00:14 -0700250static void internal_request_begin(grpc_exec_ctx *exec_ctx,
251 grpc_httpcli_context *context,
Craig Tillerc97065d2016-06-07 13:00:14 -0700252 grpc_polling_entity *pollent,
Craig Tiller20afa3d2016-10-17 14:52:14 -0700253 grpc_resource_quota *resource_quota,
Craig Tiller5b15afd2016-05-04 15:00:14 -0700254 const grpc_httpcli_request *request,
255 gpr_timespec deadline, grpc_closure *on_done,
256 grpc_httpcli_response *response,
257 const char *name, gpr_slice request_text) {
Craig Tillera82950e2015-09-22 12:33:20 -0700258 internal_request *req = gpr_malloc(sizeof(internal_request));
259 memset(req, 0, sizeof(*req));
Craig Tiller47a708e2015-09-15 16:16:06 -0700260 req->request_text = request_text;
Craig Tiller5b15afd2016-05-04 15:00:14 -0700261 grpc_http_parser_init(&req->parser, GRPC_HTTP_RESPONSE, response);
262 req->on_done = on_done;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800263 req->deadline = deadline;
Craig Tillera82950e2015-09-22 12:33:20 -0700264 req->handshaker =
265 request->handshaker ? request->handshaker : &grpc_httpcli_plaintext;
Craig Tillera0abe372015-06-01 11:31:08 -0700266 req->context = context;
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -0700267 req->pollent = pollent;
Craig Tiller6a64bfd2016-05-09 13:05:03 -0700268 req->overall_error = GRPC_ERROR_NONE;
Craig Tiller20afa3d2016-10-17 14:52:14 -0700269 req->resource_quota = grpc_resource_quota_internal_ref(resource_quota);
Craig Tillera82950e2015-09-22 12:33:20 -0700270 grpc_closure_init(&req->on_read, on_read, req);
271 grpc_closure_init(&req->done_write, done_write, req);
272 gpr_slice_buffer_init(&req->incoming);
273 gpr_slice_buffer_init(&req->outgoing);
274 grpc_iomgr_register_object(&req->iomgr_obj, name);
275 req->host = gpr_strdup(request->host);
Craig Tillercc0535d2015-12-08 15:14:47 -0800276 req->ssl_host_override = gpr_strdup(request->ssl_host_override);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800277
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -0700278 GPR_ASSERT(pollent);
David Garcia Quintasc4d51122016-06-06 14:56:02 -0700279 grpc_polling_entity_add_to_pollset_set(exec_ctx, req->pollent,
David Garcia Quintas69ff63d2016-06-06 16:39:47 -0700280 req->context->pollset_set);
Craig Tiller24d687e2016-04-13 19:47:27 -0700281 grpc_resolve_address(exec_ctx, request->host, req->handshaker->default_port,
Craig Tiller5b15afd2016-05-04 15:00:14 -0700282 grpc_closure_create(on_resolved, req), &req->addresses);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800283}
284
Craig Tillera82950e2015-09-22 12:33:20 -0700285void grpc_httpcli_get(grpc_exec_ctx *exec_ctx, grpc_httpcli_context *context,
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -0700286 grpc_polling_entity *pollent,
Craig Tiller20afa3d2016-10-17 14:52:14 -0700287 grpc_resource_quota *resource_quota,
Craig Tillera82950e2015-09-22 12:33:20 -0700288 const grpc_httpcli_request *request,
Craig Tiller5b15afd2016-05-04 15:00:14 -0700289 gpr_timespec deadline, grpc_closure *on_done,
290 grpc_httpcli_response *response) {
Craig Tiller47a708e2015-09-15 16:16:06 -0700291 char *name;
Craig Tillera82950e2015-09-22 12:33:20 -0700292 if (g_get_override &&
Craig Tiller5b15afd2016-05-04 15:00:14 -0700293 g_get_override(exec_ctx, request, deadline, on_done, response)) {
Craig Tillera82950e2015-09-22 12:33:20 -0700294 return;
295 }
Matthew Iselin1824f052016-02-10 12:16:06 +1100296 gpr_asprintf(&name, "HTTP:GET:%s:%s", request->host, request->http.path);
Craig Tiller20afa3d2016-10-17 14:52:14 -0700297 internal_request_begin(exec_ctx, context, pollent, resource_quota, request,
Craig Tillere34c2852016-09-23 09:43:32 -0700298 deadline, on_done, response, name,
Craig Tillera82950e2015-09-22 12:33:20 -0700299 grpc_httpcli_format_get_request(request));
300 gpr_free(name);
Craig Tiller47a708e2015-09-15 16:16:06 -0700301}
302
Craig Tillera82950e2015-09-22 12:33:20 -0700303void grpc_httpcli_post(grpc_exec_ctx *exec_ctx, grpc_httpcli_context *context,
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -0700304 grpc_polling_entity *pollent,
Craig Tiller20afa3d2016-10-17 14:52:14 -0700305 grpc_resource_quota *resource_quota,
Craig Tillera82950e2015-09-22 12:33:20 -0700306 const grpc_httpcli_request *request,
307 const char *body_bytes, size_t body_size,
Craig Tiller5b15afd2016-05-04 15:00:14 -0700308 gpr_timespec deadline, grpc_closure *on_done,
309 grpc_httpcli_response *response) {
Craig Tillerf39f2d62015-06-06 14:43:06 -0700310 char *name;
Craig Tillera82950e2015-09-22 12:33:20 -0700311 if (g_post_override &&
312 g_post_override(exec_ctx, request, body_bytes, body_size, deadline,
Craig Tiller5b15afd2016-05-04 15:00:14 -0700313 on_done, response)) {
Craig Tillera82950e2015-09-22 12:33:20 -0700314 return;
315 }
Matthew Iselin1824f052016-02-10 12:16:06 +1100316 gpr_asprintf(&name, "HTTP:POST:%s:%s", request->host, request->http.path);
Craig Tillera82950e2015-09-22 12:33:20 -0700317 internal_request_begin(
Craig Tiller20afa3d2016-10-17 14:52:14 -0700318 exec_ctx, context, pollent, resource_quota, request, deadline, on_done,
Craig Tillere34c2852016-09-23 09:43:32 -0700319 response, name,
Craig Tiller5b15afd2016-05-04 15:00:14 -0700320 grpc_httpcli_format_post_request(request, body_bytes, body_size));
Craig Tillera82950e2015-09-22 12:33:20 -0700321 gpr_free(name);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800322}
ctiller40260c42014-12-17 17:03:15 -0800323
Craig Tillera82950e2015-09-22 12:33:20 -0700324void grpc_httpcli_set_override(grpc_httpcli_get_override get,
325 grpc_httpcli_post_override post) {
ctiller40260c42014-12-17 17:03:15 -0800326 g_get_override = get;
327 g_post_override = post;
Craig Tiller190d3602015-02-18 09:23:38 -0800328}