GRPC Core 0.10.0.0

- Main Page
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
httpcli.h
Go to the documentation of this file.
1 /*
2 *
3 * Copyright 2015, 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/pollset_set.h"
42
43 /* User agent this library reports */
44 #define GRPC_HTTPCLI_USER_AGENT "grpc-httpcli/0.0"
45 /* Maximum length of a header string of the form 'Key: Value\r\n' */
46 #define GRPC_HTTPCLI_MAX_HEADER_LENGTH 4096
47
48 /* A single header to be passed in a request */
49 typedef struct grpc_httpcli_header {
50 char *key;
51 char *value;
52 } grpc_httpcli_header;
53
54 /* Tracks in-progress http requests
55 TODO(ctiller): allow caching and capturing multiple requests for the
56 same content and combining them */
57 typedef struct grpc_httpcli_context {
58 grpc_pollset_set pollset_set;
59 } grpc_httpcli_context;
60
61 /* A request */
62 typedef struct grpc_httpcli_request {
63 /* The host name to connect to */
64 char *host;
65 /* The path of the resource to fetch */
66 char *path;
67 /* Additional headers: count and key/values; the following are supplied
68 automatically and MUST NOT be set here:
69 Host, Connection, User-Agent */
70 size_t hdr_count;
71 grpc_httpcli_header *hdrs;
72 /* whether to use ssl for the request */
73 int use_ssl;
74 } grpc_httpcli_request;
75
76 /* A response */
77 typedef struct grpc_httpcli_response {
78 /* HTTP status code */
79 int status;
80 /* Headers: count and key/values */
81 size_t hdr_count;
82 grpc_httpcli_header *hdrs;
83 /* Body: length and contents; contents are NOT null-terminated */
84 size_t body_length;
85 char *body;
86 } grpc_httpcli_response;
87
88 /* Callback for grpc_httpcli_get and grpc_httpcli_post. */
89 typedef void (*grpc_httpcli_response_cb)(void *user_data,
90 const grpc_httpcli_response *response);
91
92 void grpc_httpcli_context_init(grpc_httpcli_context *context);
93 void grpc_httpcli_context_destroy(grpc_httpcli_context *context);
94
95 /* Asynchronously perform a HTTP GET.
96 'context' specifies the http context under which to do the get
97 'pollset' indicates a grpc_pollset that is interested in the result
98 of the get - work on this pollset may be used to progress the get
99 operation
100 'request' contains request parameters - these are caller owned and can be
101 destroyed once the call returns
102 'deadline' contains a deadline for the request (or gpr_inf_future)
103 'on_response' is a callback to report results to (and 'user_data' is a user
104 supplied pointer to pass to said call) */
105 void grpc_httpcli_get(grpc_httpcli_context *context, grpc_pollset *pollset,
106 const grpc_httpcli_request *request,
107 gpr_timespec deadline,
108 grpc_httpcli_response_cb on_response, void *user_data);
109
110 /* Asynchronously perform a HTTP POST.
111 'context' specifies the http context under which to do the post
112 'pollset' indicates a grpc_pollset that is interested in the result
113 of the post - work on this pollset may be used to progress the post
114 operation
115 'request' contains request parameters - these are caller owned and can be
116 destroyed once the call returns
117 'body_bytes' and 'body_size' specify the payload for the post.
118 When there is no body, pass in NULL as body_bytes.
119 'deadline' contains a deadline for the request (or gpr_inf_future)
120 'em' points to a caller owned event manager that must be alive for the
121 lifetime of the request
122 'on_response' is a callback to report results to (and 'user_data' is a user
123 supplied pointer to pass to said call)
124 Does not support ?var1=val1&var2=val2 in the path. */
125 void grpc_httpcli_post(grpc_httpcli_context *context, grpc_pollset *pollset,
126 const grpc_httpcli_request *request,
127 const char *body_bytes, size_t body_size,
128 gpr_timespec deadline,
129 grpc_httpcli_response_cb on_response, void *user_data);
130
131 /* override functions return 1 if they handled the request, 0 otherwise */
132 typedef int (*grpc_httpcli_get_override)(const grpc_httpcli_request *request,
133 gpr_timespec deadline,
134 grpc_httpcli_response_cb on_response,
135 void *user_data);
136 typedef int (*grpc_httpcli_post_override)(const grpc_httpcli_request *request,
137 const char *body_bytes,
138 size_t body_size,
139 gpr_timespec deadline,
140 grpc_httpcli_response_cb on_response,
141 void *user_data);
142
143 void grpc_httpcli_set_override(grpc_httpcli_get_override get,
144 grpc_httpcli_post_override post);
145
146 #endif /* GRPC_INTERNAL_CORE_HTTPCLI_HTTPCLI_H */
grpc_httpcli_header::value
char * value
Definition: httpcli.h:51
grpc_httpcli_get
void grpc_httpcli_get(grpc_httpcli_context *context, grpc_pollset *pollset, const grpc_httpcli_request *request, gpr_timespec deadline, grpc_httpcli_response_cb on_response, void *user_data)
Definition: httpcli.c:231
grpc_httpcli_response::hdrs
grpc_httpcli_header * hdrs
Definition: httpcli.h:82
time.h
grpc_httpcli_request::host
char * host
Definition: httpcli.h:64
grpc_httpcli_header
struct grpc_httpcli_header grpc_httpcli_header
grpc_httpcli_request
struct grpc_httpcli_request grpc_httpcli_request
grpc_httpcli_context_init
void grpc_httpcli_context_init(grpc_httpcli_context *context)
Definition: httpcli.c:71
grpc_httpcli_context_destroy
void grpc_httpcli_context_destroy(grpc_httpcli_context *context)
Definition: httpcli.c:75
grpc_httpcli_context::pollset_set
grpc_pollset_set pollset_set
Definition: httpcli.h:58
grpc_pollset
Definition: pollset_posix.h:48
grpc_httpcli_post_override
int(* grpc_httpcli_post_override)(const grpc_httpcli_request *request, const char *body_bytes, size_t body_size, gpr_timespec deadline, grpc_httpcli_response_cb on_response, void *user_data)
Definition: httpcli.h:136
grpc_httpcli_response::body
char * body
Definition: httpcli.h:85
grpc_httpcli_response::status
int status
Definition: httpcli.h:79
grpc_httpcli_response
struct grpc_httpcli_response grpc_httpcli_response
grpc_httpcli_request::hdrs
grpc_httpcli_header * hdrs
Definition: httpcli.h:71
grpc_httpcli_get_override
int(* grpc_httpcli_get_override)(const grpc_httpcli_request *request, gpr_timespec deadline, grpc_httpcli_response_cb on_response, void *user_data)
Definition: httpcli.h:132
grpc_httpcli_response::hdr_count
size_t hdr_count
Definition: httpcli.h:81
grpc_httpcli_context
struct grpc_httpcli_context grpc_httpcli_context
grpc_httpcli_request
Definition: httpcli.h:62
grpc_httpcli_request::path
char * path
Definition: httpcli.h:66
pollset_set.h
grpc_httpcli_response::body_length
size_t body_length
Definition: httpcli.h:84
grpc_httpcli_header::key
char * key
Definition: httpcli.h:50
gpr_timespec
Definition: time.h:60
grpc_httpcli_response_cb
void(* grpc_httpcli_response_cb)(void *user_data, const grpc_httpcli_response *response)
Definition: httpcli.h:89
grpc_httpcli_request::hdr_count
size_t hdr_count
Definition: httpcli.h:70
grpc_pollset_set
Definition: pollset_set_posix.h:40
grpc_httpcli_context
Definition: httpcli.h:57
grpc_httpcli_post
void grpc_httpcli_post(grpc_httpcli_context *context, grpc_pollset *pollset, const grpc_httpcli_request *request, const char *body_bytes, size_t body_size, gpr_timespec deadline, grpc_httpcli_response_cb on_response, void *user_data)
Definition: httpcli.c:263
grpc_httpcli_response
Definition: httpcli.h:77
grpc_httpcli_request::use_ssl
int use_ssl
Definition: httpcli.h:73
grpc_httpcli_set_override
void grpc_httpcli_set_override(grpc_httpcli_get_override get, grpc_httpcli_post_override post)
Definition: httpcli.c:297
grpc_httpcli_header
Definition: httpcli.h:49