26 #if _WIN32_WINNT < _WIN32_WINNT_VISTA
27 #error "Error: http server APIs are not supported in XP"
28 #endif //_WIN32_WINNT < _WIN32_WINNT_VISTA
32 #pragma warning(disable : 6386)
39 #include "cpprest/details/http_server.h"
50 class http_windows_server;
51 struct windows_request_context;
59 void set_http_io_completion(std::function<
void(DWORD, DWORD)> http_io_completion)
61 ZeroMemory(
this,
sizeof(OVERLAPPED));
62 m_http_io_completion = http_io_completion;
69 PTP_CALLBACK_INSTANCE instance,
73 ULONG_PTR numberOfBytesTransferred,
76 CASABLANCA_UNREFERENCED_PARAMETER(io);
77 CASABLANCA_UNREFERENCED_PARAMETER(context);
78 CASABLANCA_UNREFERENCED_PARAMETER(instance);
81 p_http_overlapped->m_http_io_completion(result, (DWORD) numberOfBytesTransferred);
85 std::function<void(DWORD, DWORD)> m_http_io_completion;
97 void async_process_request(HTTP_REQUEST_ID request_id,
http::http_request msg,
const unsigned long headers_size);
103 void read_request_body_chunk();
106 void async_process_response();
108 void transmit_body();
111 void read_headers_io_completion(DWORD error_code, DWORD bytes_read);
114 void read_body_io_completion(DWORD error_code, DWORD bytes_read);
117 void send_response_io_completion(DWORD error_code, DWORD bytes_read);
120 void send_response_body_io_completion(DWORD error_code, DWORD bytes_read);
123 void cancel_request_io_completion(DWORD error_code, DWORD bytes_read);
127 std::mutex m_responseCompletedLock;
131 HTTP_REQUEST_ID m_request_id;
133 bool m_sending_in_chunks;
134 bool m_transfer_encoding;
136 size_t m_remaining_to_write;
138 HTTP_REQUEST *m_request;
139 std::unique_ptr<unsigned char[]> m_request_buffer;
141 std::unique_ptr<HTTP_UNKNOWN_HEADER []> m_headers;
142 std::vector<std::string> m_headers_buffer;
149 std::exception_ptr m_except_ptr;
155 void send_entity_body(_In_reads_(data_length)
unsigned char * data, _In_
size_t data_length);
158 void cancel_request(std::exception_ptr except_ptr);
160 std::vector<unsigned char> m_body_data;
211 class listener_registration
214 listener_registration(HTTP_URL_GROUP_ID urlGroupId)
215 : m_urlGroupId(urlGroupId)
220 HTTP_URL_GROUP_ID m_urlGroupId;
228 std::unordered_map<web::http::experimental::listener::details::http_listener_impl *, std::unique_ptr<listener_registration>> _M_registeredListeners;
231 HTTP_SERVER_SESSION_ID m_serverSessionId;
234 std::atomic<int> m_numOutstandingRequests;
238 HANDLE m_hRequestQueue;
241 TP_IO * m_threadpool_io;
245 void receive_requests();
The task_completion_event class allows you to delay the execution of a task until a condition is sati...
Definition: pplxtasks.h:2934
Represents an HTTP response.
Definition: http_msg.h:383
The web namespace contains functionality common to multiple protocols like HTTP and WebSockets...
Definition: base_uri.h:37
Class to implement HTTP server API on Windows.
Definition: http_server_httpsys.h:166
static void CALLBACK io_completion_callback(PTP_CALLBACK_INSTANCE instance, PVOID context, PVOID pOverlapped, ULONG result, ULONG_PTR numberOfBytesTransferred, PTP_IO io)
Callback for all I/O completions.
Definition: http_server_httpsys.h:68
~http_windows_server()
Releases resources held.
virtual pplx::task< void > start()
Start listening for incoming requests.
virtual pplx::task< void > stop()
Stop processing and listening for incoming requests.
virtual pplx::task< void > respond(http::http_response response)
Asynchronously sends the specified http response.
virtual pplx::task< void > register_listener(_In_ web::http::experimental::listener::details::http_listener_impl *pListener)
Registers an http listener.
virtual pplx::task< void > unregister_listener(_In_ web::http::experimental::listener::details::http_listener_impl *pListener)
Unregisters an http listener.
The Parallel Patterns Library (PPL) task class. A task object represents work that can be executed as...
Definition: pplxtasks.h:4173
Manual reset event
Definition: pplxlinux.h:84
http_windows_server()
Constructs a http_windows_server.
Represents an HTTP request.
Definition: http_msg.h:771
Reader writer lock
Definition: pplxlinux.h:140
Internal class for pointer to implementation design pattern.
Definition: http_listener.h:171
Base structure for associating internal server information with an HTTP request/response.
Definition: http_msg.h:338
Interface http listeners interact with for receiving and responding to http requests.
Definition: http_server.h:42
Class used to wrap OVERLAPPED I/O with any HTTP I/O.
Definition: http_server_httpsys.h:56
Context for http request through Windows HTTP Server API.
Definition: http_server_httpsys.h:91