HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HOM_WebServerResponse.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * COMMENTS:
7  */
8 
9 #ifndef __HOM_WebServerResponse_h__
10 #define __HOM_WebServerResponse_h__
11 
12 #include "HOM_API.h"
13 #include "HOM_Defines.h"
14 #include "HOM_Errors.h"
15 #include "HOM_Module.h"
16 #include "HOM_PtrOrNull.h"
17 
18 #include <NET/NET_WebAPI.h>
19 #include <NET/NET_WebResponse.h>
20 #include <NET/NET_HTTPDefines.h>
21 #include <NET/NET_HttpIO.h>
22 
23 #include <UT/UT_StringHolder.h>
24 
25 #include <stdexcept>
26 #include <string>
27 
28 SWIGOUT(%rename(WebServerResponse) HOM_WebServerResponse;)
29 
31 {
32 public:
34  const HOM_BinaryString &, int, const char *, bool, bool);)
36  const HOM_BinaryString &data, int status=200,
37  const char *content_type="text/html",
38  bool is_file_name=false,
39  bool delete_file=false);
40 
43  : myResponse(response)
44  { HOM_CONSTRUCT_OBJECT(this) }
45 
47  { HOM_DESTRUCT_OBJECT(this) }
48 
50 
51  void setHeader(const char *header_name, const char *header_value)
52  {
53  if (!header_name)
54  throw HOM_TypeError("header_name cannot be None");
55  if (!header_value)
56  throw HOM_TypeError("header_value cannot be None");
57  myResponse.myHeaders[header_name] = header_value;
58  }
59 
61  { return reinterpret_cast<long long>(&myResponse); }
62 
63  std::map<std::string, std::string> headers()
64  {
65  std::map<std::string, std::string> headers;
66  for (auto &&header : myResponse.myHeaders)
67  headers.emplace(
68  header.first.toStdString(), header.second.toStdString());
69  return headers;
70  }
72  {
74  label.format("{} {}", myResponse.myStatus,
75  NET_HttpIO::translateStatusCode(myResponse.myStatus));
76  return label.toStdString();
77  }
79  {
80  return myResponse.myData.toStdString();
81  }
82 
83  SWIGOUT(%ignore myResponse;)
84  NET_WebResponse myResponse;
85 
86 private:
87  void init(const std::string& data, int status, const char* content_type,
88  bool is_file_name, bool delete_file);
89 };
90 
91 #endif
std::string toStdString() const
#define HOM_DESTRUCT_OBJECT(pointer)
Definition: HOM_Module.h:1210
Response object used for responding to request in the server.
OIIO_API bool rename(string_view from, string_view to, std::string &err)
#define SWIGOUT(x)
Definition: HOM_Defines.h:24
static const char * translateStatusCode(NET_HTTPStatusCode code)
string __repr__(VtArray< T > const &self)
Definition: wrapArray.h:349
std::map< std::string, std::string > headers()
long long _getNETHTTPResponsePointer()
#define HOM_API
Definition: HOM_API.h:13
GLint GLenum GLsizei GLint GLsizei const void * data
Definition: glew.h:1379
#define HOM_CONSTRUCT_OBJECT(pointer)
Definition: HOM_Module.h:1209
HOM_WebServerResponse(const NET_WebResponse &response)
void setHeader(const char *header_name, const char *header_value)
size_t format(const char *fmt, const Args &...args)
Format a string using the same formatting codes as UTformat.
GLuint GLsizei GLsizei GLchar * label
Definition: glew.h:8986
GLsizei const GLchar *const * string
Definition: glew.h:1844