Nebula
Loading...
Searching...
No Matches
httpserver.h
Go to the documentation of this file.
1#pragma once
2#ifndef HTTP_HTTPSERVER_H
3#define HTTP_HTTPSERVER_H
4//------------------------------------------------------------------------------
16#include "core/refcounted.h"
17#include "core/singleton.h"
18#include "net/tcpserver.h"
20#include "io/textwriter.h"
24
25//------------------------------------------------------------------------------
26namespace Http
27{
81
82//------------------------------------------------------------------------------
85inline bool
87{
88 return this->isOpen;
89}
90
91//------------------------------------------------------------------------------
99inline void
101{
102 n_assert(!this->isOpen);
103 this->isSingleThreadMode = b;
104}
105
106//------------------------------------------------------------------------------
109inline bool
111{
112 return this->isSingleThreadMode;
113}
114
115//------------------------------------------------------------------------------
118inline void
120{
121 this->ipAddress.SetPort(p);
122}
123
124//------------------------------------------------------------------------------
127inline ushort
129{
130 return this->ipAddress.GetPort();
131}
132
133//------------------------------------------------------------------------------
138{
139 return this->requestHandlers.ValuesAsArray();
140}
141
142} // namespace Http
143//------------------------------------------------------------------------------
144#endif
The common base class of Nebula.
Definition refcounted.h:38
Implements an extremly simple standalone HTTP server with attached HttpRequestHandlers.
Definition httpserver.h:29
bool IsSingleThreadMode() const
get single-thread mode
Definition httpserver.h:110
void RemoveRequestHandler(const Ptr< HttpRequestHandler > &h)
remove a request handler from the server
Definition httpserver.cc:99
void OnFrame()
call this method frequently to serve http connections
Definition httpserver.cc:110
Net::IpAddress ipAddress
Definition httpserver.h:75
ushort GetPort() const
get port number of http service
Definition httpserver.h:128
Ptr< DefaultHttpRequestHandler > defaultRequestHandler
Definition httpserver.h:74
void Close()
close the http server
Definition httpserver.cc:64
bool Open()
open the http server
Definition httpserver.cc:45
Util::Array< PendingRequest > pendingRequests
Definition httpserver.h:77
Ptr< Net::TcpServer > tcpServer
Definition httpserver.h:76
bool HandleHttpRequest(const Ptr< Net::TcpClientConnection > &clientConnection)
handle an HttpRequest
Definition httpserver.cc:149
void SetSingleThreadMode(bool b)
turn single-thread mode on/off (useful for debugging), default is off
Definition httpserver.h:100
__DeclareSingleton(HttpServer)
bool BuildHttpResponse(const Ptr< Net::TcpClientConnection > &clientConnection, const Ptr< HttpRequest > &httpRequest)
build an HttpResponse for a handled http request
Definition httpserver.cc:231
bool IsOpen() const
return true if server is open
Definition httpserver.h:86
HttpServer()
constructor
Definition httpserver.cc:23
virtual ~HttpServer()
destructor
Definition httpserver.cc:35
bool isOpen
Definition httpserver.h:78
void SetPort(ushort p)
set port number for http service
Definition httpserver.h:119
Util::Dictionary< Util::String, Ptr< HttpRequestHandler > > requestHandlers
Definition httpserver.h:73
bool isSingleThreadMode
Definition httpserver.h:79
Util::Array< Ptr< HttpRequestHandler > > GetRequestHandlers() const
get registered request handlers
Definition httpserver.h:137
void AttachRequestHandler(const Ptr< HttpRequestHandler > &h)
attach a request handler to the server
Definition httpserver.cc:87
__DeclareClass(HttpServer)
Represents an IP address, consisting of a IPv4 host address and a port number.
Nebula's smart pointer class which manages the life time of RefCounted objects.
Definition ptr.h:38
Nebula's dynamic array class.
Definition array.h:60
A collection of key/value pairs with quick value retrieval by key at roughly O(log n).
Definition dictionary.h:34
#define n_assert(exp)
Definition debug.h:50
This file was generated with Nebula Trifid's idlc compiler tool.
Definition defaulthttprequesthandler.cc:15
Definition httpserver.h:68
Ptr< Net::TcpClientConnection > clientConnection
Definition httpserver.h:69
Ptr< HttpRequest > httpRequest
Definition httpserver.h:70
unsigned short ushort
Definition types.h:32