gRPC  0.6.0
 All Classes Namespaces Functions Variables Enumerations Properties Pages
httpcli.h
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 /* User agent this library reports */
42 #define GRPC_HTTPCLI_USER_AGENT "grpc-httpcli/0.0"
43 /* Maximum length of a header string of the form 'Key: Value\r\n' */
44 #define GRPC_HTTPCLI_MAX_HEADER_LENGTH 4096
45 
46 /* A single header to be passed in a request */
47 typedef struct grpc_httpcli_header {
48  char *key;
49  char *value;
51 
52 /* A request */
53 typedef struct grpc_httpcli_request {
54  /* The host name to connect to */
55  char *host;
56  /* The path of the resource to fetch */
57  char *path;
58  /* Additional headers: count and key/values; the following are supplied
59  automatically and MUST NOT be set here:
60  Host, Connection, User-Agent */
61  size_t hdr_count;
62  grpc_httpcli_header *hdrs;
63  /* whether to use ssl for the request */
64  int use_ssl;
66 
67 /* A response */
68 typedef struct grpc_httpcli_response {
69  /* HTTP status code */
70  int status;
71  /* Headers: count and key/values */
72  size_t hdr_count;
73  grpc_httpcli_header *hdrs;
74  /* Body: length and contents; contents are NOT null-terminated */
75  size_t body_length;
76  char *body;
78 
79 /* Callback for grpc_httpcli_get */
80 typedef void (*grpc_httpcli_response_cb)(void *user_data,
81  const grpc_httpcli_response *response);
82 
83 /* Asynchronously perform a HTTP GET.
84  'request' contains request parameters - these are caller owned and can be
85  destroyed once the call returns
86  'deadline' contains a deadline for the request (or gpr_inf_future)
87  'em' points to a caller owned event manager that must be alive for the
88  lifetime of the request
89  'on_response' is a callback to report results to (and 'user_data' is a user
90  supplied pointer to pass to said call) */
91 void grpc_httpcli_get(const grpc_httpcli_request *request,
92  gpr_timespec deadline,
93  grpc_httpcli_response_cb on_response, void *user_data);
94 
95 /* Asynchronously perform a HTTP POST.
96  When there is no body, pass in NULL as body_bytes.
97  Does not support ?var1=val1&var2=val2 in the path. */
98 void grpc_httpcli_post(const grpc_httpcli_request *request,
99  const char *body_bytes, size_t body_size,
100  gpr_timespec deadline,
101  grpc_httpcli_response_cb on_response, void *user_data);
102 
103 /* override functions return 1 if they handled the request, 0 otherwise */
104 typedef int (*grpc_httpcli_get_override)(const grpc_httpcli_request *request,
105  gpr_timespec deadline,
106  grpc_httpcli_response_cb on_response,
107  void *user_data);
108 typedef int (*grpc_httpcli_post_override)(const grpc_httpcli_request *request,
109  const char *body_bytes,
110  size_t body_size,
111  gpr_timespec deadline,
112  grpc_httpcli_response_cb on_response,
113  void *user_data);
114 
115 void grpc_httpcli_set_override(grpc_httpcli_get_override get,
116  grpc_httpcli_post_override post);
117 
118 #endif /* GRPC_INTERNAL_CORE_HTTPCLI_HTTPCLI_H */
Definition: httpcli.h:53
Definition: time.h:48
Definition: channel_create.c:62
Definition: httpcli.h:68
Definition: httpcli.h:47