TensorFlow Serving C++ API Documentation
httpclient_interface.h
1 /* Copyright 2020 Google Inc. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7  http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #ifndef THIRD_PARTY_TENSORFLOW_SERVING_UTIL_NET_HTTP_CLIENT_TEST_CLIENT_PUBLIC_HTTPCLIENT_INTERFACE_H_
17 #define THIRD_PARTY_TENSORFLOW_SERVING_UTIL_NET_HTTP_CLIENT_TEST_CLIENT_PUBLIC_HTTPCLIENT_INTERFACE_H_
18 
19 #include "tensorflow_serving/util/net_http/public/response_code_enum.h"
20 #include "tensorflow_serving/util/net_http/server/public/httpserver_interface.h"
21 
22 // API for the HTTP Client
23 // NOTE: This API is not yet finalized, and should be considered experimental.
24 
25 namespace tensorflow {
26 namespace serving {
27 namespace net_http {
28 
29 // Data to be copied
31  typedef std::pair<absl::string_view, absl::string_view> HeaderKeyValue;
32 
33  absl::string_view uri_path;
34  absl::string_view method; // must be in upper-case
35  std::vector<HeaderKeyValue> headers;
36  absl::string_view body;
37 };
38 
39 // Caller allocates the data for output
41  typedef std::pair<std::string, std::string> HeaderKeyValue;
42 
43  HTTPStatusCode status = HTTPStatusCode::UNDEFINED;
44  std::vector<HeaderKeyValue> headers;
45  std::string body;
46 
47  std::function<void()> done; // callback
48 };
49 
50 // This interface class specifies the API contract for the HTTP client.
52  public:
53  TestHTTPClientInterface(const TestHTTPClientInterface& other) = delete;
54  TestHTTPClientInterface& operator=(const TestHTTPClientInterface& other) =
55  delete;
56 
57  virtual ~TestHTTPClientInterface() = default;
58 
59  // Terminates the connection.
60  virtual void Terminate() = 0;
61 
62  // Sends a request and blocks the caller till a response is received
63  // or any error has happened.
64  // Returns false if any error.
65  virtual bool BlockingSendRequest(const TestClientRequest& request,
66  TestClientResponse* response) = 0;
67 
68  // Sends a request and returns immediately. The response will be handled
69  // asynchronously via the response->done callback.
70  // Returns false if any error in sending the request, or if the executor
71  // has not been configured.
72  virtual bool SendRequest(const TestClientRequest& request,
73  TestClientResponse* response) = 0;
74 
75  // Sets the executor for processing requests asynchronously.
76  virtual void SetExecutor(std::unique_ptr<EventExecutor> executor) = 0;
77 
78  protected:
79  TestHTTPClientInterface() = default;
80 };
81 
82 } // namespace net_http
83 } // namespace serving
84 } // namespace tensorflow
85 
86 #endif // THIRD_PARTY_TENSORFLOW_SERVING_UTIL_NET_HTTP_CLIENT_TEST_CLIENT_PUBLIC_HTTPCLIENT_INTERFACE_H_