Skip to Content
Internet Protocol
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
Variable

Idle Timeout Seconds

  • Set/Get timeout value in seconds. Idle connections are closed after this time.
  • Since 4.0 the default is 60 (it was 0, never). 0 disables it.
Idle Timeout Seconds
Variable

Use Tls

  • New in 4.0. Encrypts the connection with TLS. With no Set Tls Options call, the secure default options are used.
  • Applies to the next connection.
Use Tls
Variable

Response Timeout Seconds

  • New in 4.0. A request whose handler has not called Write after this many seconds is answered with 503. Default 30, 0 = never.
Response Timeout Seconds
Variable

Max Header Bytes

  • New in 4.0. Largest request line + headers accepted. Larger requests get 431. Default 64 KiB.
Max Header Bytes
Variable

Max Body Bytes

  • New in 4.0. Largest request body accepted. Larger requests get 413. Default 64 MiB.
Max Body Bytes
Variable

Functions

Is Open

  • Return true if socket is open.
Is Open
Return Value
Pure function

Local Endpoint

  • Get the local endpoint of the socket. Use this function only after open connection.
Local Endpoint
Return Value
Pure function

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 Close arrives.
Clients
Return Value
Pure function

Get Error Code

  • Return a struct of the latest error code returned by asio.
Get Error Code
Return Value
Pure function

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.
  • Address must be an IP literal, localhost or empty (any address). Host names are not resolved: they, and ports outside 0-65535, fail with an Invalid argument error.
OpenTarget is Http Server
Target
Bind Opts
Return Value
Function

Close

  • Close the underlying socket and stop listening for data on it. 'on_close' event will be triggered.
CloseTarget is Http Server
Target
Function

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, 501 or 505, and the connection is closed.
  • Requests pipelined on the same connection are answered in the order they arrived.
  • Responses to HEAD requests are sent without a body.

Routes and parameters (4.0)

  • Routes are case-sensitive. Exact routes are tried first.
  • :name segments and a trailing * capture values into Route Params of the request. For example /users/:id matches /users/42 with id = 42, and /files/* matches everything below /files/.
  • A path that exists only for other methods gets 405 Method Not Allowed with an Allow header.
  • HEAD falls back to the GET route when there is no HEAD route.
  • Expect: 100-continue is answered automatically.
  • A handler that sets Connection: close in the response closes the connection after it is sent.
  • A handler that never calls Write gets an automatic 503 after Response Timeout Seconds.
  • The parser rejects malformed headers (bare LF, folded lines, spaces before :), CR/LF in the path or host, HTTP/1.1 requests without Host and ambiguous framing.

All

  • Create a callback to receive requests of any methods for a specific path.
AllTarget is Http Server
Target
Path
Callback
Function
On AllCustom Event
Request
Response
Event

Get

  • Create a callback to receive requests of get method for a specific path.
GetTarget is Http Server
Target
Path
Callback
Function
On GetCustom Event
Request
Response
Event

Post

  • Create a callback to receive requests of post method for a specific path.
PostTarget is Http Server
Target
Path
Callback
Function
On PostCustom Event
Request
Response
Event

Put

  • Create a callback to receive requests of put method for a specific path.
PutTarget is Http Server
Target
Path
Callback
Function
On PutCustom Event
Request
Response
Event

Del

  • Create a callback to receive requests of del method for a specific path.
DelTarget is Http Server
Target
Path
Callback
Function
On DelCustom Event
Request
Response
Event
  • Create a callback to receive requests of head method for a specific path.
HeadTarget is Http Server
Target
Path
Callback
Function
On HeadCustom Event
Request
Response
Event

Options

  • Create a callback to receive requests of options method for a specific path.
OptionsTarget is Http Server
Target
Path
Callback
Function
On OptionsCustom Event
Request
Response
Event

Patch

  • Create a callback to receive requests of patch method for a specific path.
PatchTarget is Http Server
Target
Path
Callback
Function
On PatchCustom Event
Request
Response
Event

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
Function

Events

On Close

  • Event triggered when socket is closed.
Bind Event to On Close
Target
Event
On CloseCustom Event
Event binding

On Error

  • Event triggered if any error occur during async process.
Bind Event to On Error
Target
Event
On ErrorCustom Event
Error Code
Event binding

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, Body or Body Bytes. See HTTP Response.
Headers
Variable

Write

  • Sends the response in Headers. Each request must be answered once.
WriteTarget is HttpRemote
Target
Callback
Return Value
Function

Begin Stream

  • New in 4.0. Starts a streamed response with the current Headers (status and headers, no Content-Length).
  • Send the body with Write Chunk / Write Chunk Buffer and finish with End Stream. HTTP/1.1 uses chunked encoding; HTTP/1.0 streams until the connection closes.
Begin StreamTarget is HttpRemote
Target
Return Value
Function

Write Chunk

  • New in 4.0. Sends a text part of a streamed response.
Write ChunkTarget is HttpRemote
Target
Data
Return Value
Function

Write Chunk Buffer

  • New in 4.0. Sends a binary part of a streamed response.
Write Chunk BufferTarget is HttpRemote
Target
Data
Return Value
Function

End Stream

  • New in 4.0. Finishes a streamed response.
End StreamTarget is HttpRemote
Target
Return Value
Function

Is Open

  • Return true if the connection is open.
Is Open
Return Value
Pure function

Local Endpoint

  • Local endpoint of the connection.
Local Endpoint
Return Value
Pure function

Remote Endpoint

  • Address and port of the client.
Remote Endpoint
Return Value
Pure function

Get Error Code

  • Return a struct of the latest error code.
Get Error Code
Return Value
Pure function

Close

  • Closes the connection.
CloseTarget is HttpRemote
Target
Function

Remote Events

On Close

  • The connection was closed.
Bind Event to On Close
Target
Event
On CloseCustom Event
Event binding

On Error

  • An error happened on this connection.
Bind Event to On Error
Target
Event
On ErrorCustom Event
Error Code
Event binding
Edit on GitHub

On this page