From 2368dc53d0c724f1899aeb2874ba1a763e11f0b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Mon, 29 Jan 2024 15:40:26 +0100 Subject: Cowboy 2.11 --- .../cowboy/2.11/manual/cowboy_req.reply/index.html | 237 +++++++++++++++++++++ 1 file changed, 237 insertions(+) create mode 100644 docs/en/cowboy/2.11/manual/cowboy_req.reply/index.html (limited to 'docs/en/cowboy/2.11/manual/cowboy_req.reply') diff --git a/docs/en/cowboy/2.11/manual/cowboy_req.reply/index.html b/docs/en/cowboy/2.11/manual/cowboy_req.reply/index.html new file mode 100644 index 00000000..5227e32e --- /dev/null +++ b/docs/en/cowboy/2.11/manual/cowboy_req.reply/index.html @@ -0,0 +1,237 @@ + + + + + + + + + + Nine Nines: cowboy_req:reply(3) + + + + + + + + + + + + + + + +
+
+
+
+ +

cowboy_req:reply(3)

+ +

Name

+

cowboy_req:reply - Send the response

+

Description

+
+
reply(Status, Req :: cowboy_req:req())
+    -> reply(StatusCode, #{}, Req)
+
+reply(Status, Headers, Req :: cowboy_req:req())
+    -> Req
+
+reply(Status, Headers, Body, Req :: cowboy_req:req())
+    -> Req
+
+Status  :: cowboy:http_status()
+Headers :: cowboy:http_headers()
+Body    :: cowboy_req:resp_body()
+
+

Send the response.

+

The header names must be given as lowercase binary strings. While header names are case insensitive, Cowboy requires them to be given as lowercase to function properly.

+

Cowboy does not allow duplicate header names. Headers set by this function may overwrite those set by set_resp_header/3 and set_resp_headers/2.

+

Use cowboy_req:set_resp_cookie(3) instead of this function to set cookies.

+

The reply/2,3 functions will send the body set previously, if any. The reply/4 function always sends the given body, overriding any previously set.

+

You do not need to set the content-length header when sending a response body. Cowboy takes care of it automatically. You should however provide a content-type header.

+

No further data can be transmitted after this function returns. This includes the push mechanism. Attempting to send two replies, or to push resources after a reply has been sent, will result in an error.

+

Arguments

+
Status
+

The status code for the response.

+
+
Headers
+

The response headers.

+

Header names must be given as lowercase binary strings.

+
+
Body
+

The body can be either a binary value, an iolist or a sendfile tuple telling Cowboy to send the contents of a file.

+
+
Req
+

The Req object.

+
+
+

Return value

+

A new Req object is returned.

+

The returned Req object should be used from that point onward as it contains updated information about the state of the request.

+

Changelog

+
  • 2.0: Only the Req is returned, it is no longer wrapped in a tuple. +
  • +
  • 1.0: Function introduced. +
  • +
+

Examples

+
Reply
+
+
Req = cowboy_req:reply(404, Req0).
+
+
Reply with custom headers
+
+
Req = cowboy_req:reply(401, #{
+    <<"www-authenticate">> => <<"Basic realm=\"erlang.org\"">>
+}, Req0).
+
+
Reply with custom headers and a body
+
+
Req = cowboy_req:reply(200, #{
+    <<"content-type">> => <<"text/plain">>
+}, "Hello world!", Req0).
+
+

See also

+

cowboy_req(3), cowboy_req:set_resp_cookie(3), cowboy_req:set_resp_header(3), cowboy_req:set_resp_headers(3), cowboy_req:set_resp_body(3), cowboy_req:inform(3), cowboy_req:stream_reply(3), cowboy_req:push(3)

+ + + + + + +
+ +
+ + +

+ Cowboy + 2.11 + Function Reference + +

+ + + +

Navigation

+ +

Version select

+ + +

Like my work? Donate!

+

Donate to Loïc Hoguin because his work on Cowboy, Ranch, Gun and Erlang.mk is fantastic:

+
+ + + + + + + + + +

Recurring payment options are also available via GitHub Sponsors. These funds are used to cover the recurring expenses like food, dedicated servers or domain names.

+ + + +
+
+
+
+ + + + + + + + + -- cgit v1.2.3