Skip to content

Latest commit

 

History

History
114 lines (76 loc) · 2.47 KB

HttpResponse.md

File metadata and controls

114 lines (76 loc) · 2.47 KB

HttpResponse

Extends: Reference

Description

A response object useful to send out responses

Property Descriptions

client

var client: StreamPeer

The client currently talking to the server

server_identifier

var server_identifier: String = "GodotTPD"

The server identifier to use on responses [GodotTPD]

headers

var headers: Dictionary

A dictionary of headers Headers can be set using the set(name, value) function

cookies

var cookies: Array

An array of cookies Cookies can be set using the cookie(name, value, options) function Cookies will be automatically sent via "Set-Cookie" headers to clients

Method Descriptions

send_raw

func send_raw(status_code: int, data: PoolByteArray, content_type: String = "application/octet-stream") -> void

Send out a raw (Bytes) response to the client Useful to send files faster or raw data which will be converted by the client

Parameters

  • status: The HTTP status code to send
  • data: The body data to send []
  • content_type: The type of the content to send ["text/html"]

send

func send(status_code: int, data: String = "", content_type = "text/html") -> void

Send out a response to the client

Parameters

  • status: The HTTP status code to send
  • data: The body data to send []
  • content_type: The type of the content to send ["text/html"]

json

func json(status_code: int, data) -> void

Send out a JSON response to the client This function will internally call the send() method

Parameters

  • status_code: The HTTP status code to send
  • data: The body data to send, must be a Dictionary or an Array

set

func set(field: String, value: String) -> void

Sets the response’s header "field" to "value"

Parameters

  • field: the name of the header i.e. "Accept-Type"
  • value: the value of this header i.e. "application/json"

cookie

func cookie(name: String, value: String, options: Dictionary) -> void

Sets cookie "name" to "value"

Parameters

  • name: the name of the cookie i.e. "user-id"
  • value: the value of this cookie i.e. "abcdef"
  • options: a Dictionary of cookie attributes for this specific cookie, in the { "secure" : "true" } format