blob: fdb8abaa2df1f67399b8042c27f4fdc3304ee172 [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"
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080035
36#include <string.h>
37
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080038#include <grpc/support/alloc.h>
39#include <grpc/support/log.h>
Masood Malekghassemi701af602015-06-03 15:01:17 -070040#include <grpc/support/string_util.h>
Craig Tiller6a64bfd2016-05-09 13:05:03 -070041#include <grpc/support/useful.h>
Craig Tiller1d7704d2016-02-25 14:07:29 -080042
Craig Tiller9533d042016-03-25 17:11:06 -070043#include "src/core/lib/http/format_request.h"
44#include "src/core/lib/http/parser.h"
45#include "src/core/lib/iomgr/endpoint.h"
46#include "src/core/lib/iomgr/iomgr_internal.h"
47#include "src/core/lib/iomgr/resolve_address.h"
Craig Tiller6a64bfd2016-05-09 13:05:03 -070048#include "src/core/lib/iomgr/sockaddr_utils.h"
Craig Tiller9533d042016-03-25 17:11:06 -070049#include "src/core/lib/iomgr/tcp_client.h"
50#include "src/core/lib/support/string.h"
Craig Tiller69b093b2016-02-25 19:04:07 -080051
Craig Tillera82950e2015-09-22 12:33:20 -070052typedef struct {
Craig Tillerd41a4a72016-10-26 16:16:06 -070053 grpc_slice request_text;
Matthew Iselin1824f052016-02-10 12:16:06 +110054 grpc_http_parser parser;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080055 grpc_resolved_addresses *addresses;
56 size_t next_address;
57 grpc_endpoint *ep;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080058 char *host;
Craig Tillercc0535d2015-12-08 15:14:47 -080059 char *ssl_host_override;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080060 gpr_timespec deadline;
61 int have_read_byte;
Craig Tillerf53d9c82015-08-04 14:19:43 -070062 const grpc_httpcli_handshaker *handshaker;
Craig Tiller5b15afd2016-05-04 15:00:14 -070063 grpc_closure *on_done;
Craig Tillera0abe372015-06-01 11:31:08 -070064 grpc_httpcli_context *context;
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -070065 grpc_polling_entity *pollent;
Craig Tillerf39f2d62015-06-06 14:43:06 -070066 grpc_iomgr_object iomgr_obj;
Craig Tillerd41a4a72016-10-26 16:16:06 -070067 grpc_slice_buffer incoming;
68 grpc_slice_buffer outgoing;
Craig Tiller33825112015-09-18 07:44:19 -070069 grpc_closure on_read;
70 grpc_closure done_write;
Craig Tillerd1bec032015-09-18 17:29:00 -070071 grpc_closure connected;
Craig Tiller6a64bfd2016-05-09 13:05:03 -070072 grpc_error *overall_error;
Craig Tiller20afa3d2016-10-17 14:52:14 -070073 grpc_resource_quota *resource_quota;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080074} internal_request;
75
ctiller40260c42014-12-17 17:03:15 -080076static grpc_httpcli_get_override g_get_override = NULL;
77static grpc_httpcli_post_override g_post_override = NULL;
78
Craig Tillera82950e2015-09-22 12:33:20 -070079static void plaintext_handshake(grpc_exec_ctx *exec_ctx, void *arg,
80 grpc_endpoint *endpoint, const char *host,
Craig Tiller449c64b2016-06-13 16:26:50 -070081 gpr_timespec deadline,
Craig Tillera82950e2015-09-22 12:33:20 -070082 void (*on_done)(grpc_exec_ctx *exec_ctx,
83 void *arg,
84 grpc_endpoint *endpoint)) {
85 on_done(exec_ctx, arg, endpoint);
Craig Tillerf53d9c82015-08-04 14:19:43 -070086}
87
Craig Tillera82950e2015-09-22 12:33:20 -070088const grpc_httpcli_handshaker grpc_httpcli_plaintext = {"http",
89 plaintext_handshake};
Craig Tillerf53d9c82015-08-04 14:19:43 -070090
Craig Tillera82950e2015-09-22 12:33:20 -070091void grpc_httpcli_context_init(grpc_httpcli_context *context) {
Craig Tiller69b093b2016-02-25 19:04:07 -080092 context->pollset_set = grpc_pollset_set_create();
Craig Tillera0abe372015-06-01 11:31:08 -070093}
94
Craig Tillera82950e2015-09-22 12:33:20 -070095void grpc_httpcli_context_destroy(grpc_httpcli_context *context) {
Craig Tiller69b093b2016-02-25 19:04:07 -080096 grpc_pollset_set_destroy(context->pollset_set);
Craig Tillera0abe372015-06-01 11:31:08 -070097}
98
Craig Tiller6a64bfd2016-05-09 13:05:03 -070099static void next_address(grpc_exec_ctx *exec_ctx, internal_request *req,
100 grpc_error *due_to_error);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800101
Craig Tillera82950e2015-09-22 12:33:20 -0700102static void finish(grpc_exec_ctx *exec_ctx, internal_request *req,
Craig Tiller5b15afd2016-05-04 15:00:14 -0700103 grpc_error *error) {
David Garcia Quintasc4d51122016-06-06 14:56:02 -0700104 grpc_polling_entity_del_from_pollset_set(exec_ctx, req->pollent,
David Garcia Quintas69ff63d2016-06-06 16:39:47 -0700105 req->context->pollset_set);
Craig Tiller332f1b32016-05-24 13:21:21 -0700106 grpc_exec_ctx_sched(exec_ctx, req->on_done, error, NULL);
Matthew Iselin1824f052016-02-10 12:16:06 +1100107 grpc_http_parser_destroy(&req->parser);
Craig Tillera82950e2015-09-22 12:33:20 -0700108 if (req->addresses != NULL) {
109 grpc_resolved_addresses_destroy(req->addresses);
110 }
111 if (req->ep != NULL) {
112 grpc_endpoint_destroy(exec_ctx, req->ep);
113 }
Craig Tillerd41a4a72016-10-26 16:16:06 -0700114 grpc_slice_unref(req->request_text);
Craig Tillera82950e2015-09-22 12:33:20 -0700115 gpr_free(req->host);
Craig Tillercc0535d2015-12-08 15:14:47 -0800116 gpr_free(req->ssl_host_override);
Craig Tillera82950e2015-09-22 12:33:20 -0700117 grpc_iomgr_unregister_object(&req->iomgr_obj);
Craig Tillerd41a4a72016-10-26 16:16:06 -0700118 grpc_slice_buffer_destroy(&req->incoming);
119 grpc_slice_buffer_destroy(&req->outgoing);
Craig Tiller6a64bfd2016-05-09 13:05:03 -0700120 GRPC_ERROR_UNREF(req->overall_error);
Craig Tiller20afa3d2016-10-17 14:52:14 -0700121 grpc_resource_quota_internal_unref(exec_ctx, req->resource_quota);
Craig Tillera82950e2015-09-22 12:33:20 -0700122 gpr_free(req);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800123}
124
Craig Tiller6a64bfd2016-05-09 13:05:03 -0700125static void append_error(internal_request *req, grpc_error *error) {
126 if (req->overall_error == GRPC_ERROR_NONE) {
127 req->overall_error = GRPC_ERROR_CREATE("Failed HTTP/1 client request");
128 }
129 grpc_resolved_address *addr = &req->addresses->addrs[req->next_address - 1];
murgatroid997871f732016-09-23 13:49:05 -0700130 char *addr_text = grpc_sockaddr_to_uri(addr);
Craig Tiller6a64bfd2016-05-09 13:05:03 -0700131 req->overall_error = grpc_error_add_child(
132 req->overall_error,
133 grpc_error_set_str(error, GRPC_ERROR_STR_TARGET_ADDRESS, addr_text));
134 gpr_free(addr_text);
135}
136
Craig Tillera82950e2015-09-22 12:33:20 -0700137static void do_read(grpc_exec_ctx *exec_ctx, internal_request *req) {
138 grpc_endpoint_read(exec_ctx, req->ep, &req->incoming, &req->on_read);
Craig Tillerb0298592015-08-27 07:38:01 -0700139}
140
Craig Tillerc027e772016-05-03 16:27:00 -0700141static void on_read(grpc_exec_ctx *exec_ctx, void *user_data,
142 grpc_error *error) {
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800143 internal_request *req = user_data;
144 size_t i;
145
Craig Tillere6deeb12016-05-09 13:14:32 -0700146 for (i = 0; i < req->incoming.count; i++) {
Craig Tiller618e67d2016-10-26 21:08:10 -0700147 if (GRPC_SLICE_LENGTH(req->incoming.slices[i])) {
Craig Tillera82950e2015-09-22 12:33:20 -0700148 req->have_read_byte = 1;
Craig Tillere6deeb12016-05-09 13:14:32 -0700149 grpc_error *err =
Mark D. Roth714c7ec2016-08-04 12:58:16 -0700150 grpc_http_parser_parse(&req->parser, req->incoming.slices[i], NULL);
Craig Tillere6deeb12016-05-09 13:14:32 -0700151 if (err != GRPC_ERROR_NONE) {
152 finish(exec_ctx, req, err);
153 return;
154 }
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800155 }
Craig Tillera82950e2015-09-22 12:33:20 -0700156 }
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800157
Craig Tillerc027e772016-05-03 16:27:00 -0700158 if (error == GRPC_ERROR_NONE) {
Craig Tillera82950e2015-09-22 12:33:20 -0700159 do_read(exec_ctx, req);
160 } else if (!req->have_read_byte) {
Craig Tiller6a64bfd2016-05-09 13:05:03 -0700161 next_address(exec_ctx, req, GRPC_ERROR_REF(error));
Craig Tillera82950e2015-09-22 12:33:20 -0700162 } else {
Craig Tillere6deeb12016-05-09 13:14:32 -0700163 finish(exec_ctx, req, grpc_http_parser_eof(&req->parser));
Craig Tillera82950e2015-09-22 12:33:20 -0700164 }
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800165}
166
Craig Tillera82950e2015-09-22 12:33:20 -0700167static void on_written(grpc_exec_ctx *exec_ctx, internal_request *req) {
168 do_read(exec_ctx, req);
Craig Tillerd1bec032015-09-18 17:29:00 -0700169}
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800170
Craig Tillerc027e772016-05-03 16:27:00 -0700171static void done_write(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800172 internal_request *req = arg;
Craig Tillerc027e772016-05-03 16:27:00 -0700173 if (error == GRPC_ERROR_NONE) {
Craig Tillera82950e2015-09-22 12:33:20 -0700174 on_written(exec_ctx, req);
175 } else {
Craig Tiller6a64bfd2016-05-09 13:05:03 -0700176 next_address(exec_ctx, req, GRPC_ERROR_REF(error));
Craig Tillera82950e2015-09-22 12:33:20 -0700177 }
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800178}
179
Craig Tillera82950e2015-09-22 12:33:20 -0700180static void start_write(grpc_exec_ctx *exec_ctx, internal_request *req) {
Craig Tillerd41a4a72016-10-26 16:16:06 -0700181 grpc_slice_ref(req->request_text);
182 grpc_slice_buffer_add(&req->outgoing, req->request_text);
Craig Tillera82950e2015-09-22 12:33:20 -0700183 grpc_endpoint_write(exec_ctx, req->ep, &req->outgoing, &req->done_write);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800184}
185
Craig Tillera82950e2015-09-22 12:33:20 -0700186static void on_handshake_done(grpc_exec_ctx *exec_ctx, void *arg,
187 grpc_endpoint *ep) {
Craig Tillerf53d9c82015-08-04 14:19:43 -0700188 internal_request *req = arg;
189
Craig Tillera82950e2015-09-22 12:33:20 -0700190 if (!ep) {
Craig Tiller6a64bfd2016-05-09 13:05:03 -0700191 next_address(exec_ctx, req,
192 GRPC_ERROR_CREATE("Unexplained handshake failure"));
Craig Tillera82950e2015-09-22 12:33:20 -0700193 return;
194 }
Craig Tillerf53d9c82015-08-04 14:19:43 -0700195
196 req->ep = ep;
Craig Tillera82950e2015-09-22 12:33:20 -0700197 start_write(exec_ctx, req);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800198}
199
Craig Tillerc027e772016-05-03 16:27:00 -0700200static void on_connected(grpc_exec_ctx *exec_ctx, void *arg,
201 grpc_error *error) {
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800202 internal_request *req = arg;
203
Craig Tillera82950e2015-09-22 12:33:20 -0700204 if (!req->ep) {
Craig Tiller6a64bfd2016-05-09 13:05:03 -0700205 next_address(exec_ctx, req, GRPC_ERROR_REF(error));
Craig Tillera82950e2015-09-22 12:33:20 -0700206 return;
207 }
Craig Tillercc0535d2015-12-08 15:14:47 -0800208 req->handshaker->handshake(
209 exec_ctx, req, req->ep,
210 req->ssl_host_override ? req->ssl_host_override : req->host,
Craig Tiller449c64b2016-06-13 16:26:50 -0700211 req->deadline, on_handshake_done);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800212}
213
Craig Tiller6a64bfd2016-05-09 13:05:03 -0700214static void next_address(grpc_exec_ctx *exec_ctx, internal_request *req,
215 grpc_error *error) {
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800216 grpc_resolved_address *addr;
Craig Tiller6a64bfd2016-05-09 13:05:03 -0700217 if (error != GRPC_ERROR_NONE) {
218 append_error(req, error);
219 }
Craig Tillera82950e2015-09-22 12:33:20 -0700220 if (req->next_address == req->addresses->naddrs) {
Craig Tiller6a64bfd2016-05-09 13:05:03 -0700221 finish(exec_ctx, req,
222 GRPC_ERROR_CREATE_REFERENCING("Failed HTTP requests to all targets",
223 &req->overall_error, 1));
Craig Tillera82950e2015-09-22 12:33:20 -0700224 return;
225 }
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800226 addr = &req->addresses->addrs[req->next_address++];
Craig Tillera82950e2015-09-22 12:33:20 -0700227 grpc_closure_init(&req->connected, on_connected, req);
Craig Tiller86958762016-09-23 12:05:34 -0700228 grpc_arg arg;
Craig Tiller153eaa72016-10-21 13:52:36 -0700229 arg.key = GRPC_ARG_RESOURCE_QUOTA;
Craig Tiller86958762016-09-23 12:05:34 -0700230 arg.type = GRPC_ARG_POINTER;
Craig Tiller20afa3d2016-10-17 14:52:14 -0700231 arg.value.pointer.p = req->resource_quota;
232 arg.value.pointer.vtable = grpc_resource_quota_arg_vtable();
Craig Tiller86958762016-09-23 12:05:34 -0700233 grpc_channel_args args = {1, &arg};
murgatroid99dedb9232016-09-26 13:54:04 -0700234 grpc_tcp_client_connect(exec_ctx, &req->connected, &req->ep,
Craig Tiller3d357d92016-10-26 20:52:03 -0700235 req->context->pollset_set, &args, addr,
236 req->deadline);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800237}
238
Craig Tiller5b15afd2016-05-04 15:00:14 -0700239static void on_resolved(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800240 internal_request *req = arg;
Craig Tiller5b15afd2016-05-04 15:00:14 -0700241 if (error != GRPC_ERROR_NONE) {
242 finish(exec_ctx, req, error);
Craig Tillera82950e2015-09-22 12:33:20 -0700243 return;
244 }
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800245 req->next_address = 0;
Craig Tiller6a64bfd2016-05-09 13:05:03 -0700246 next_address(exec_ctx, req, GRPC_ERROR_NONE);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800247}
248
Craig Tiller5b15afd2016-05-04 15:00:14 -0700249static void internal_request_begin(grpc_exec_ctx *exec_ctx,
250 grpc_httpcli_context *context,
Craig Tillerc97065d2016-06-07 13:00:14 -0700251 grpc_polling_entity *pollent,
Craig Tiller20afa3d2016-10-17 14:52:14 -0700252 grpc_resource_quota *resource_quota,
Craig Tiller5b15afd2016-05-04 15:00:14 -0700253 const grpc_httpcli_request *request,
254 gpr_timespec deadline, grpc_closure *on_done,
255 grpc_httpcli_response *response,
Craig Tillerd41a4a72016-10-26 16:16:06 -0700256 const char *name, grpc_slice request_text) {
Craig Tillera82950e2015-09-22 12:33:20 -0700257 internal_request *req = gpr_malloc(sizeof(internal_request));
258 memset(req, 0, sizeof(*req));
Craig Tiller47a708e2015-09-15 16:16:06 -0700259 req->request_text = request_text;
Craig Tiller5b15afd2016-05-04 15:00:14 -0700260 grpc_http_parser_init(&req->parser, GRPC_HTTP_RESPONSE, response);
261 req->on_done = on_done;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800262 req->deadline = deadline;
Craig Tillera82950e2015-09-22 12:33:20 -0700263 req->handshaker =
264 request->handshaker ? request->handshaker : &grpc_httpcli_plaintext;
Craig Tillera0abe372015-06-01 11:31:08 -0700265 req->context = context;
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -0700266 req->pollent = pollent;
Craig Tiller6a64bfd2016-05-09 13:05:03 -0700267 req->overall_error = GRPC_ERROR_NONE;
Craig Tiller20afa3d2016-10-17 14:52:14 -0700268 req->resource_quota = grpc_resource_quota_internal_ref(resource_quota);
Craig Tillera82950e2015-09-22 12:33:20 -0700269 grpc_closure_init(&req->on_read, on_read, req);
270 grpc_closure_init(&req->done_write, done_write, req);
Craig Tillerd41a4a72016-10-26 16:16:06 -0700271 grpc_slice_buffer_init(&req->incoming);
272 grpc_slice_buffer_init(&req->outgoing);
Craig Tillera82950e2015-09-22 12:33:20 -0700273 grpc_iomgr_register_object(&req->iomgr_obj, name);
274 req->host = gpr_strdup(request->host);
Craig Tillercc0535d2015-12-08 15:14:47 -0800275 req->ssl_host_override = gpr_strdup(request->ssl_host_override);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800276
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -0700277 GPR_ASSERT(pollent);
David Garcia Quintasc4d51122016-06-06 14:56:02 -0700278 grpc_polling_entity_add_to_pollset_set(exec_ctx, req->pollent,
David Garcia Quintas69ff63d2016-06-06 16:39:47 -0700279 req->context->pollset_set);
Craig Tiller24d687e2016-04-13 19:47:27 -0700280 grpc_resolve_address(exec_ctx, request->host, req->handshaker->default_port,
Craig Tiller5b15afd2016-05-04 15:00:14 -0700281 grpc_closure_create(on_resolved, req), &req->addresses);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800282}
283
Craig Tillera82950e2015-09-22 12:33:20 -0700284void grpc_httpcli_get(grpc_exec_ctx *exec_ctx, grpc_httpcli_context *context,
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -0700285 grpc_polling_entity *pollent,
Craig Tiller20afa3d2016-10-17 14:52:14 -0700286 grpc_resource_quota *resource_quota,
Craig Tillera82950e2015-09-22 12:33:20 -0700287 const grpc_httpcli_request *request,
Craig Tiller5b15afd2016-05-04 15:00:14 -0700288 gpr_timespec deadline, grpc_closure *on_done,
289 grpc_httpcli_response *response) {
Craig Tiller47a708e2015-09-15 16:16:06 -0700290 char *name;
Craig Tillera82950e2015-09-22 12:33:20 -0700291 if (g_get_override &&
Craig Tiller5b15afd2016-05-04 15:00:14 -0700292 g_get_override(exec_ctx, request, deadline, on_done, response)) {
Craig Tillera82950e2015-09-22 12:33:20 -0700293 return;
294 }
Matthew Iselin1824f052016-02-10 12:16:06 +1100295 gpr_asprintf(&name, "HTTP:GET:%s:%s", request->host, request->http.path);
Craig Tiller20afa3d2016-10-17 14:52:14 -0700296 internal_request_begin(exec_ctx, context, pollent, resource_quota, request,
Craig Tillere34c2852016-09-23 09:43:32 -0700297 deadline, on_done, response, name,
Craig Tillera82950e2015-09-22 12:33:20 -0700298 grpc_httpcli_format_get_request(request));
299 gpr_free(name);
Craig Tiller47a708e2015-09-15 16:16:06 -0700300}
301
Craig Tillera82950e2015-09-22 12:33:20 -0700302void grpc_httpcli_post(grpc_exec_ctx *exec_ctx, grpc_httpcli_context *context,
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -0700303 grpc_polling_entity *pollent,
Craig Tiller20afa3d2016-10-17 14:52:14 -0700304 grpc_resource_quota *resource_quota,
Craig Tillera82950e2015-09-22 12:33:20 -0700305 const grpc_httpcli_request *request,
306 const char *body_bytes, size_t body_size,
Craig Tiller5b15afd2016-05-04 15:00:14 -0700307 gpr_timespec deadline, grpc_closure *on_done,
308 grpc_httpcli_response *response) {
Craig Tillerf39f2d62015-06-06 14:43:06 -0700309 char *name;
Craig Tillera82950e2015-09-22 12:33:20 -0700310 if (g_post_override &&
311 g_post_override(exec_ctx, request, body_bytes, body_size, deadline,
Craig Tiller5b15afd2016-05-04 15:00:14 -0700312 on_done, response)) {
Craig Tillera82950e2015-09-22 12:33:20 -0700313 return;
314 }
Matthew Iselin1824f052016-02-10 12:16:06 +1100315 gpr_asprintf(&name, "HTTP:POST:%s:%s", request->host, request->http.path);
Craig Tillera82950e2015-09-22 12:33:20 -0700316 internal_request_begin(
Craig Tiller20afa3d2016-10-17 14:52:14 -0700317 exec_ctx, context, pollent, resource_quota, request, deadline, on_done,
Craig Tillere34c2852016-09-23 09:43:32 -0700318 response, name,
Craig Tiller5b15afd2016-05-04 15:00:14 -0700319 grpc_httpcli_format_post_request(request, body_bytes, body_size));
Craig Tillera82950e2015-09-22 12:33:20 -0700320 gpr_free(name);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800321}
ctiller40260c42014-12-17 17:03:15 -0800322
Craig Tillera82950e2015-09-22 12:33:20 -0700323void grpc_httpcli_set_override(grpc_httpcli_get_override get,
324 grpc_httpcli_post_override post) {
ctiller40260c42014-12-17 17:03:15 -0800325 g_get_override = get;
326 g_post_override = post;
Craig Tiller190d3602015-02-18 09:23:38 -0800327}