GRPC C++  1.26.0
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 
44 typedef struct {
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));
50 
53 
54 /* A request */
55 typedef struct grpc_httpcli_request {
56  /* The host name to connect to */
57  char* host;
58  /* The host to verify in the SSL handshake (or NULL) */
60  /* The main part of the request
61  The following headers are supplied automatically and MUST NOT be set here:
62  Host, Connection, User-Agent */
64  /* handshaker to use ssl for the request */
67 
68 /* Expose the parser response type as a httpcli response too */
70 
73 
74 /* Asynchronously perform a HTTP GET.
75  'context' specifies the http context under which to do the get
76  'pollset' indicates a grpc_pollset that is interested in the result
77  of the get - work on this pollset may be used to progress the get
78  operation
79  'request' contains request parameters - these are caller owned and can be
80  destroyed once the call returns
81  'deadline' contains a deadline for the request (or gpr_inf_future)
82  'on_response' is a callback to report results to */
84  grpc_polling_entity* pollent,
85  grpc_resource_quota* resource_quota,
86  const grpc_httpcli_request* request, grpc_millis deadline,
87  grpc_closure* on_complete,
88  grpc_httpcli_response* response);
89 
90 /* Asynchronously perform a HTTP POST.
91  'context' specifies the http context under which to do the post
92  'pollset' indicates a grpc_pollset that is interested in the result
93  of the post - work on this pollset may be used to progress the post
94  operation
95  'request' contains request parameters - these are caller owned and can be
96  destroyed once the call returns
97  'body_bytes' and 'body_size' specify the payload for the post.
98  When there is no body, pass in NULL as body_bytes.
99  'deadline' contains a deadline for the request (or gpr_inf_future)
100  'em' points to a caller owned event manager that must be alive for the
101  lifetime of the request
102  'on_response' is a callback to report results to
103  Does not support ?var1=val1&var2=val2 in the path. */
105  grpc_polling_entity* pollent,
106  grpc_resource_quota* resource_quota,
107  const grpc_httpcli_request* request,
108  const char* body_bytes, size_t body_size,
109  grpc_millis deadline, grpc_closure* on_complete,
110  grpc_httpcli_response* response);
111 
112 /* override functions return 1 if they handled the request, 0 otherwise */
113 typedef int (*grpc_httpcli_get_override)(const grpc_httpcli_request* request,
114  grpc_millis deadline,
115  grpc_closure* on_complete,
116  grpc_httpcli_response* response);
117 typedef int (*grpc_httpcli_post_override)(const grpc_httpcli_request* request,
118  const char* body_bytes,
119  size_t body_size,
120  grpc_millis deadline,
121  grpc_closure* on_complete,
122  grpc_httpcli_response* response);
123 
126 
127 #endif /* GRPC_CORE_LIB_HTTP_HTTPCLI_H */
Definition: httpcli.h:44
int64_t grpc_millis
Definition: exec_ctx.h:35
const char * default_port
Definition: httpcli.h:45
Definition: parser.h:55
char * ssl_host_override
Definition: httpcli.h:59
Definition: parser.h:71
char * host
Definition: httpcli.h:57
struct grpc_httpcli_request grpc_httpcli_request
grpc_pollset_set * pollset_set
Definition: httpcli.h:41
const grpc_httpcli_handshaker * handshaker
Definition: httpcli.h:65
void grpc_httpcli_context_init(grpc_httpcli_context *context)
void grpc_httpcli_context_destroy(grpc_httpcli_context *context)
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:117
Definition: polling_entity.h:37
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_complete, grpc_httpcli_response *response)
const grpc_httpcli_handshaker grpc_httpcli_plaintext
struct grpc_pollset_set grpc_pollset_set
Definition: pollset_set.h:31
grpc_http_request http
Definition: httpcli.h:63
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_complete, grpc_httpcli_response *response)
A closure over a grpc_iomgr_cb_func.
Definition: closure.h:56
struct grpc_httpcli_context grpc_httpcli_context
Definition: httpcli.h:55
Definition: endpoint.h:102
struct grpc_resource_quota grpc_resource_quota
Definition: grpc_types.h:677
Definition: httpcli.h:40
const grpc_httpcli_handshaker grpc_httpcli_ssl
int(* grpc_httpcli_get_override)(const grpc_httpcli_request *request, grpc_millis deadline, grpc_closure *on_complete, grpc_httpcli_response *response)
Definition: httpcli.h:113
void grpc_httpcli_set_override(grpc_httpcli_get_override get, grpc_httpcli_post_override post)