Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(377)

Side by Side Diff: third_party/grpc/src/core/httpcli/httpcli.h

Issue 1932353002: Initial checkin of gRPC to third_party/ Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 *
3 * Copyright 2015-2016, Google Inc.
4 * 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
34 #ifndef GRPC_INTERNAL_CORE_HTTPCLI_HTTPCLI_H
35 #define GRPC_INTERNAL_CORE_HTTPCLI_HTTPCLI_H
36
37 #include <stddef.h>
38
39 #include <grpc/support/time.h>
40
41 #include "src/core/iomgr/endpoint.h"
42 #include "src/core/iomgr/iomgr_internal.h"
43 #include "src/core/iomgr/pollset_set.h"
44
45 /* User agent this library reports */
46 #define GRPC_HTTPCLI_USER_AGENT "grpc-httpcli/0.0"
47 /* Maximum length of a header string of the form 'Key: Value\r\n' */
48 #define GRPC_HTTPCLI_MAX_HEADER_LENGTH 4096
49
50 /* A single header to be passed in a request */
51 typedef struct grpc_httpcli_header {
52 char *key;
53 char *value;
54 } grpc_httpcli_header;
55
56 /* Tracks in-progress http requests
57 TODO(ctiller): allow caching and capturing multiple requests for the
58 same content and combining them */
59 typedef struct grpc_httpcli_context {
60 grpc_pollset_set *pollset_set;
61 } grpc_httpcli_context;
62
63 typedef struct {
64 const char *default_port;
65 void (*handshake)(grpc_exec_ctx *exec_ctx, void *arg, grpc_endpoint *endpoint,
66 const char *host,
67 void (*on_done)(grpc_exec_ctx *exec_ctx, void *arg,
68 grpc_endpoint *endpoint));
69 } grpc_httpcli_handshaker;
70
71 extern const grpc_httpcli_handshaker grpc_httpcli_plaintext;
72 extern const grpc_httpcli_handshaker grpc_httpcli_ssl;
73
74 /* A request */
75 typedef struct grpc_httpcli_request {
76 /* The host name to connect to */
77 char *host;
78 /* The host to verify in the SSL handshake (or NULL) */
79 char *ssl_host_override;
80 /* The path of the resource to fetch */
81 char *path;
82 /* Additional headers: count and key/values; the following are supplied
83 automatically and MUST NOT be set here:
84 Host, Connection, User-Agent */
85 size_t hdr_count;
86 grpc_httpcli_header *hdrs;
87 /* handshaker to use ssl for the request */
88 const grpc_httpcli_handshaker *handshaker;
89 } grpc_httpcli_request;
90
91 /* A response */
92 typedef struct grpc_httpcli_response {
93 /* HTTP status code */
94 int status;
95 /* Headers: count and key/values */
96 size_t hdr_count;
97 grpc_httpcli_header *hdrs;
98 /* Body: length and contents; contents are NOT null-terminated */
99 size_t body_length;
100 char *body;
101 } grpc_httpcli_response;
102
103 /* Callback for grpc_httpcli_get and grpc_httpcli_post. */
104 typedef void (*grpc_httpcli_response_cb)(grpc_exec_ctx *exec_ctx,
105 void *user_data,
106 const grpc_httpcli_response *response);
107
108 void grpc_httpcli_context_init(grpc_httpcli_context *context);
109 void grpc_httpcli_context_destroy(grpc_httpcli_context *context);
110
111 /* Asynchronously perform a HTTP GET.
112 'context' specifies the http context under which to do the get
113 'pollset' indicates a grpc_pollset that is interested in the result
114 of the get - work on this pollset may be used to progress the get
115 operation
116 'request' contains request parameters - these are caller owned and can be
117 destroyed once the call returns
118 'deadline' contains a deadline for the request (or gpr_inf_future)
119 'on_response' is a callback to report results to (and 'user_data' is a user
120 supplied pointer to pass to said call) */
121 void grpc_httpcli_get(grpc_exec_ctx *exec_ctx, grpc_httpcli_context *context,
122 grpc_pollset *pollset,
123 const grpc_httpcli_request *request,
124 gpr_timespec deadline,
125 grpc_httpcli_response_cb on_response, void *user_data);
126
127 /* Asynchronously perform a HTTP POST.
128 'context' specifies the http context under which to do the post
129 'pollset' indicates a grpc_pollset that is interested in the result
130 of the post - work on this pollset may be used to progress the post
131 operation
132 'request' contains request parameters - these are caller owned and can be
133 destroyed once the call returns
134 'body_bytes' and 'body_size' specify the payload for the post.
135 When there is no body, pass in NULL as body_bytes.
136 'deadline' contains a deadline for the request (or gpr_inf_future)
137 'em' points to a caller owned event manager that must be alive for the
138 lifetime of the request
139 'on_response' is a callback to report results to (and 'user_data' is a user
140 supplied pointer to pass to said call)
141 Does not support ?var1=val1&var2=val2 in the path. */
142 void grpc_httpcli_post(grpc_exec_ctx *exec_ctx, grpc_httpcli_context *context,
143 grpc_pollset *pollset,
144 const grpc_httpcli_request *request,
145 const char *body_bytes, size_t body_size,
146 gpr_timespec deadline,
147 grpc_httpcli_response_cb on_response, void *user_data);
148
149 /* override functions return 1 if they handled the request, 0 otherwise */
150 typedef int (*grpc_httpcli_get_override)(grpc_exec_ctx *exec_ctx,
151 const grpc_httpcli_request *request,
152 gpr_timespec deadline,
153 grpc_httpcli_response_cb on_response,
154 void *user_data);
155 typedef int (*grpc_httpcli_post_override)(
156 grpc_exec_ctx *exec_ctx, const grpc_httpcli_request *request,
157 const char *body_bytes, size_t body_size, gpr_timespec deadline,
158 grpc_httpcli_response_cb on_response, void *user_data);
159
160 void grpc_httpcli_set_override(grpc_httpcli_get_override get,
161 grpc_httpcli_post_override post);
162
163 #endif /* GRPC_INTERNAL_CORE_HTTPCLI_HTTPCLI_H */
OLDNEW
« no previous file with comments | « third_party/grpc/src/core/httpcli/format_request.c ('k') | third_party/grpc/src/core/httpcli/httpcli.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698