Unreal Engine Plugin
HTTP Server
HTTP server for Unreal Engine: Blueprint nodes, events and C++ usage with the Internet Protocol plugin.
References
#include "http/httpserver.h"
How to use
Blueprint: search by GetInternetProtocolSubsystem and call CreateHttpServer function
C++: Use the code bellow
#include "http/httpserver.h"
UHttpServer* net = NewObject<UHttpServer>();Variables
Backlog
- Set/Get the maximum number of simultaneous client connections the server will accept in queue.
Backlog
Idle Timeout Seconds
- Set/Get timeout value in seconds. Idle connections are closed after this time.
- Since 4.0 the default is
60(it was0, never).0disables it.
Idle Timeout Seconds
Use Tls
- New in 4.0. Encrypts the connection with TLS. With no
Set Tls Optionscall, the secure default options are used. - Applies to the next connection.
Use Tls
Response Timeout Seconds
- New in 4.0. A request whose handler has not called
Writeafter this many seconds is answered with503. Default30,0= never.
Response Timeout Seconds
Max Header Bytes
- New in 4.0. Largest request line + headers accepted. Larger requests get
431. Default 64 KiB.
Max Header Bytes
Max Body Bytes
- New in 4.0. Largest request body accepted. Larger requests get
413. Default 64 MiB.
Max Body Bytes
Functions
Is Open
- Return true if socket is open.
Is Open
Return Value
Local Endpoint
- Get the local endpoint of the socket. Use this function only after open connection.
Local Endpoint
Return Value
Clients
- Returns a copy of the set of clients connected to the server (a reference before 4.0).
- A client stays in the set until its own
On Closearrives.
Clients
Return Value
Get Error Code
- Return a struct of the latest error code returned by asio.
Get Error Code
Return Value
Open
- Opens the TCP server and starts listening for incoming connections.
- It returns false if socket is already open or if asio return any error code during the bind.
Addressmust be an IP literal,localhostor empty (any address). Host names are not resolved: they, and ports outside 0-65535, fail with anInvalid argumenterror.
OpenTarget is Http Server
Target
Bind Opts
Return Value
Close
- Close the underlying socket and stop listening for data on it. 'on_close' event will be triggered.
CloseTarget is Http Server
Target
Routing
Requests are routed on the Game Thread to the callbacks below.
- A request whose path has no callback is answered automatically with
404 Not Found. - A malformed request is answered automatically with
400,413,431,501or505, and the connection is closed. - Requests pipelined on the same connection are answered in the order they arrived.
- Responses to
HEADrequests are sent without a body.
Routes and parameters (4.0)
- Routes are case-sensitive. Exact routes are tried first.
:namesegments and a trailing*capture values intoRoute Paramsof the request. For example/users/:idmatches/users/42withid = 42, and/files/*matches everything below/files/.- A path that exists only for other methods gets
405 Method Not Allowedwith anAllowheader. HEADfalls back to theGETroute when there is noHEADroute.Expect: 100-continueis answered automatically.- A handler that sets
Connection: closein the response closes the connection after it is sent. - A handler that never calls
Writegets an automatic503afterResponse Timeout Seconds. - The parser rejects malformed headers (bare LF, folded lines, spaces before
:), CR/LF in the path or host, HTTP/1.1 requests withoutHostand ambiguous framing.
All
- Create a callback to receive requests of any methods for a specific path.
AllTarget is Http Server
Target
Path
Callback
On AllCustom Event
Request
Response
Get
- Create a callback to receive requests of get method for a specific path.
GetTarget is Http Server
Target
Path
Callback
On GetCustom Event
Request
Response
Post
- Create a callback to receive requests of post method for a specific path.
PostTarget is Http Server
Target
Path
Callback
On PostCustom Event
Request
Response
Put
- Create a callback to receive requests of put method for a specific path.
PutTarget is Http Server
Target
Path
Callback
On PutCustom Event
Request
Response
Del
- Create a callback to receive requests of del method for a specific path.
DelTarget is Http Server
Target
Path
Callback
On DelCustom Event
Request
Response
Head
- Create a callback to receive requests of head method for a specific path.
HeadTarget is Http Server
Target
Path
Callback
On HeadCustom Event
Request
Response
Options
- Create a callback to receive requests of options method for a specific path.
OptionsTarget is Http Server
Target
Path
Callback
On OptionsCustom Event
Request
Response
Patch
- Create a callback to receive requests of patch method for a specific path.
PatchTarget is Http Server
Target
Path
Callback
On PatchCustom Event
Request
Response
Set Tls Options
- New in 4.0. Turns TLS on with these options. See Security Context Options.
- A TLS server needs a certificate and a private key.
- Applies to the next connection.
Set Tls OptionsTarget is Http Server
Target
Sec Opts
Events
On Close
- Event triggered when socket is closed.
Bind Event to On Close
Target
Event
On CloseCustom Event
On Error
- Event triggered if any error occur during async process.
Bind Event to On Error
Target
Event
On ErrorCustom Event
Error Code
Remote
Each route callback receives the request and an Http Remote (UHttpRemote), the connection that will carry the response. Fill its Headers (status, headers and body) and call Write. In 4.0 the TLS server gives the same class: HttpRemoteSsl was merged into it.
Headers
- The response to send:
Status Code,Headers,Header List,BodyorBody Bytes. See HTTP Response.
Headers
Write
- Sends the response in
Headers. Each request must be answered once.
WriteTarget is HttpRemote
Target
Callback
Return Value
Begin Stream
- New in 4.0. Starts a streamed response with the current
Headers(status and headers, noContent-Length). - Send the body with
Write Chunk/Write Chunk Bufferand finish withEnd Stream. HTTP/1.1 uses chunked encoding; HTTP/1.0 streams until the connection closes.
Begin StreamTarget is HttpRemote
Target
Return Value
Write Chunk
- New in 4.0. Sends a text part of a streamed response.
Write ChunkTarget is HttpRemote
Target
Data
Return Value
Write Chunk Buffer
- New in 4.0. Sends a binary part of a streamed response.
Write Chunk BufferTarget is HttpRemote
Target
Data
Return Value
End Stream
- New in 4.0. Finishes a streamed response.
End StreamTarget is HttpRemote
Target
Return Value
Is Open
- Return true if the connection is open.
Is Open
Return Value
Local Endpoint
- Local endpoint of the connection.
Local Endpoint
Return Value
Remote Endpoint
- Address and port of the client.
Remote Endpoint
Return Value
Get Error Code
- Return a struct of the latest error code.
Get Error Code
Return Value
Close
- Closes the connection.
CloseTarget is HttpRemote
Target
Remote Events
On Close
- The connection was closed.
Bind Event to On Close
Target
Event
On CloseCustom Event
On Error
- An error happened on this connection.
Bind Event to On Error
Target
Event
On ErrorCustom Event
Error Code