Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ytake/hack-cookie
HHVM and Hack Cookies for facebook/hack-http-request-response-interfaces
https://github.com/ytake/hack-cookie
cookie hack hacklang hhvm http
Last synced: 25 days ago
JSON representation
HHVM and Hack Cookies for facebook/hack-http-request-response-interfaces
- Host: GitHub
- URL: https://github.com/ytake/hack-cookie
- Owner: ytake
- License: mit
- Created: 2020-04-09T11:41:57.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-07-14T04:42:28.000Z (over 4 years ago)
- Last Synced: 2024-10-05T22:03:32.922Z (3 months ago)
- Topics: cookie, hack, hacklang, hhvm, http
- Language: Hack
- Homepage:
- Size: 45.9 KB
- Stars: 1
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Hack Cookie
[![Build Status](https://travis-ci.org/ytake/hack-cookie.svg?branch=master)](https://travis-ci.org/ytake/hack-cookie)
Managing Cookies for [facebook/hack-http-request-response-interfaces](https://github.com/hhvm/hack-http-request-response-interfaces).
Supported Only Hack library.
Required HHVM >= 4.41.0- [ytake/hungrr](https://github.com/ytake/hungrr)
- [usox/hackttp](https://github.com/usox/hackttp)## Installation
```bash
$> composer require ytake/hack-cookie
```## Basic Usage
### Request Cookies
```hack
use type Ytake\HackCookie\Cookie;$cookie = Cookie::create('theme', 'blue');
```#### Get a Request Cookie
```hack
use type Ytake\HackCookie\RequestCookies;
use type Ytake\Hungrr\{Request, Uri};
use namespace HH\Lib\IO;$request = new Request(Message\HTTPMethod::GET, new Uri('/'), IO\request_input);
$cookie = RequestCookies::get($request, 'theme');
$cookie = RequestCookies::get($request, 'theme', 'default-theme');
```#### Set a Request Cookie
```hack
use type Ytake\HackCookie\RequestCookies;
use type Ytake\Hungrr\{Request, Uri};
use namespace HH\Lib\IO;$request = new Request(Message\HTTPMethod::GET, new Uri('/'), IO\request_input);
$request = RequestCookies::set($request, Cookie::create('theme', 'blue'));
```#### Modify a Request Cookie
```hack
use type Ytake\HackCookie\{Cookie, Cookies, RequestCookies};
use type Ytake\Hungrr\{Request, Uri};
use namespace HH\Lib\IO;$modify = (Cookie $cookie) ==> {
return $cookie->getValue()
|> $cookie->withValue($$);
}
$request = new Request(Message\HTTPMethod::GET, new Uri('/'), IO\request_input);
$request = RequestCookies::modify($request, 'theme', $modify);
```### Response Cookies
```hack
use type Ytake\HackCookie\{SameSite, SetCookie};SetCookie::create('lu')
->withValue('Rg3vHJZnehYLjVg7qi3bZjzg')
->withExpires(new \DateTime('Tue, 15-Jan-2020 21:47:38 GMT'))
->withMaxAge(500)
->withPath('/')
->withDomain('.example.com')
->withSecure(true)
->withHttpOnly(true)
->withSameSite(SameSite::LAX);
```and more.