GRPC C++  1.39.1
httpcli.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPC_CORE_LIB_HTTP_HTTPCLI_H
20 #define GRPC_CORE_LIB_HTTP_HTTPCLI_H
21 
23 
24 #include <stddef.h>
25 
26 #include <grpc/support/time.h>
27 
33 
34 /* User agent this library reports */
35 #define GRPC_HTTPCLI_USER_AGENT "grpc-httpcli/0.0"
36 
37 /* Tracks in-progress http requests
38  TODO(ctiller): allow caching and capturing multiple requests for the
39  same content and combining them */
40 typedef struct grpc_httpcli_context {
43 
45  const char* default_port;
46  void (*handshake)(void* arg, grpc_endpoint* endpoint, const char* host,
47  grpc_millis deadline,
48  void (*on_done)(void* arg, grpc_endpoint* endpoint));
49 };
52 
53 /* A request */
54 typedef struct grpc_httpcli_request {
55  /* The host name to connect to */
56  char* host;
57  /* The host to verify in the SSL handshake (or NULL) */
59  /* The main part of the request
60  The following headers are supplied automatically and MUST NOT be set here:
61  Host, Connection, User-Agent */
63  /* handshaker to use ssl for the request */
66 
67 /* Expose the parser response type as a httpcli response too */
69 
72 
73 /* Asynchronously perform a HTTP GET.
74  'context' specifies the http context under which to do the get
75  'pollset' indicates a grpc_pollset that is interested in the result
76  of the get - work on this pollset may be used to progress the get
77  operation
78  'request' contains request parameters - these are caller owned and can be
79  destroyed once the call returns
80  'deadline' contains a deadline for the request (or gpr_inf_future)
81  'on_response' is a callback to report results to */
83  grpc_polling_entity* pollent,
84  grpc_resource_quota* resource_quota,
85  const grpc_httpcli_request* request, grpc_millis deadline,
86  grpc_closure* on_done, grpc_httpcli_response* response);
87 
88 /* Asynchronously perform a HTTP POST.
89  'context' specifies the http context under which to do the post
90  'pollset' indicates a grpc_pollset that is interested in the result
91  of the post - work on this pollset may be used to progress the post
92  operation
93  'request' contains request parameters - these are caller owned and can be
94  destroyed once the call returns
95  'body_bytes' and 'body_size' specify the payload for the post.
96  When there is no body, pass in NULL as body_bytes.
97  'deadline' contains a deadline for the request (or gpr_inf_future)
98  'em' points to a caller owned event manager that must be alive for the
99  lifetime of the request
100  'on_response' is a callback to report results to
101  Does not support ?var1=val1&var2=val2 in the path. */
103  grpc_polling_entity* pollent,
104  grpc_resource_quota* resource_quota,
105  const grpc_httpcli_request* request,
106  const char* body_bytes, size_t body_size,
107  grpc_millis deadline, grpc_closure* on_done,
108  grpc_httpcli_response* response);
109 
110 /* override functions return 1 if they handled the request, 0 otherwise */
111 typedef int (*grpc_httpcli_get_override)(const grpc_httpcli_request* request,
112  grpc_millis deadline,
113  grpc_closure* on_complete,
114  grpc_httpcli_response* response);
115 typedef int (*grpc_httpcli_post_override)(const grpc_httpcli_request* request,
116  const char* body_bytes,
117  size_t body_size,
118  grpc_millis deadline,
119  grpc_closure* on_complete,
120  grpc_httpcli_response* response);
121 
124 
125 #endif /* GRPC_CORE_LIB_HTTP_HTTPCLI_H */
int64_t grpc_millis
Definition: exec_ctx.h:37
void grpc_httpcli_get(grpc_httpcli_context *context, grpc_polling_entity *pollent, grpc_resource_quota *resource_quota, const grpc_httpcli_request *request, grpc_millis deadline, grpc_closure *on_done, grpc_httpcli_response *response)
Definition: httpcli.cc:268
void grpc_httpcli_set_override(grpc_httpcli_get_override get, grpc_httpcli_post_override post)
Definition: httpcli.cc:302
int(* grpc_httpcli_post_override)(const grpc_httpcli_request *request, const char *body_bytes, size_t body_size, grpc_millis deadline, grpc_closure *on_complete, grpc_httpcli_response *response)
Definition: httpcli.h:115
int(* grpc_httpcli_get_override)(const grpc_httpcli_request *request, grpc_millis deadline, grpc_closure *on_complete, grpc_httpcli_response *response)
Definition: httpcli.h:111
void grpc_httpcli_context_destroy(grpc_httpcli_context *context)
Definition: httpcli.cc:85
const grpc_httpcli_handshaker grpc_httpcli_ssl
Definition: httpcli_security_connector.cc:218
struct grpc_httpcli_request grpc_httpcli_request
const grpc_httpcli_handshaker grpc_httpcli_plaintext
Definition: httpcli.cc:78
void grpc_httpcli_post(grpc_httpcli_context *context, grpc_polling_entity *pollent, grpc_resource_quota *resource_quota, const grpc_httpcli_request *request, const char *body_bytes, size_t body_size, grpc_millis deadline, grpc_closure *on_done, grpc_httpcli_response *response)
Definition: httpcli.cc:283
void grpc_httpcli_context_init(grpc_httpcli_context *context)
Definition: httpcli.cc:81
struct grpc_httpcli_context grpc_httpcli_context
struct grpc_pollset_set grpc_pollset_set
Definition: pollset_set.h:31
A closure over a grpc_iomgr_cb_func.
Definition: closure.h:56
Definition: endpoint.h:106
Definition: parser.h:55
Definition: parser.h:71
Definition: httpcli.h:40
grpc_pollset_set * pollset_set
Definition: httpcli.h:41
Definition: httpcli.h:44
void(* handshake)(void *arg, grpc_endpoint *endpoint, const char *host, grpc_millis deadline, void(*on_done)(void *arg, grpc_endpoint *endpoint))
Definition: httpcli.h:46
const char * default_port
Definition: httpcli.h:45
Definition: httpcli.h:54
char * ssl_host_override
Definition: httpcli.h:58
const grpc_httpcli_handshaker * handshaker
Definition: httpcli.h:64
char * host
Definition: httpcli.h:56
grpc_http_request http
Definition: httpcli.h:62
Definition: polling_entity.h:37
Definition: resource_quota.cc:127