Skip to content

Add detailed info about cookies and example #1057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions doc/reference/reference_lua/http.rst
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,49 @@ Below is a list of all ``http`` functions.

:rtype: table

The ``cookies`` component contains a Lua table where the key is a cookie
name. The value is an array of two elements where the first one is the
cookie value and the second one is an array with the cookie’s options.
Possible options are: "Expires", "Max-Age", "Domain", "Path", "Secure",
"HttpOnly", "SameSite". Note that an option is a string with '='
splitting the option's name and its value.
`Here <https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies>`_
you can find more info.

**Example**

You can use cookies information like this:

.. code-block:: tarantoolsession

tarantool> require('http.client').get('https://www.tarantool.io/en/').cookies
---
- csrftoken:
- bWJVkBybvX9LdJ8uLPOTVrit5P3VbRjE3potYVOuUnsSjYT5ahghDV06tXRkfnOl
- - Max-Age=31449600
- Path=/
...

tarantool> cookies = require('http.client').get('https://www.tarantool.io/en/').cookies
---
...

tarantool> options = cookies['csrftoken'][2]
---
...

tarantool> for _, option in ipairs(options) do
> if option:startswith('csrftoken cookie's Max-Age = ') then
> print(option)
> end
> end

csrftoken cookie's Max-Age = 31449600
---
...

tarantool>

The following "shortcuts" exist for requests:

* ``http_client:get(url, options)`` - shortcut for
Expand Down