Skip to content

Commit abd6518

Browse files
committed
init
1 parent 29a13e1 commit abd6518

File tree

10 files changed

+219
-2
lines changed

10 files changed

+219
-2
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
composer.phar
2+
composer.lock
3+
vendor/

.hhconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
assume_php=false
2+
enable_experimental_tc_features = no_fallback_in_namespaces
3+
safe_array=true
4+
safe_vector_array=true

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2018 Yuuki Takezawa
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

100644100755
Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,52 @@
1-
# http-request-handler
2-
for Hack
1+
# HTTP Server Request Handlers
2+
3+
PSR-15 Like HTTP Server Request Handlers Interface For Hack
4+
5+
## Require
6+
7+
HHVM 3.30.0 and above.
8+
required [hsl-experimental](https://github.com/hhvm/hsl-experimental)
9+
10+
## Install
11+
12+
```bash
13+
$ hhvm $(which composer) require ytake/hack-http-server-request-handlers-interfaces
14+
```
15+
16+
## Usage
17+
18+
Golang style
19+
20+
```go
21+
func middleware(next http.HandlerFunc) http.HandlerFunc {
22+
return func(w http.ResponseWriter, r *http.Request) {
23+
log.Printf("Hello World, %s", r.RequestURI)
24+
next.ServeHTTP(w, r)
25+
}
26+
}
27+
```
28+
29+
For Hack
30+
31+
```hack
32+
<?hh // strict
33+
34+
namespace Acme\Middleware;
35+
36+
use type HH\Lib\Experimental\IO\WriteHandle;
37+
use type Facebook\Experimental\Http\Message\ResponseInterface;
38+
use type Facebook\Experimental\Http\Message\ServerRequestInterface;
39+
use type Nazg\Http\Server\MiddlewareInterface;
40+
use type Nazg\Http\Server\RequestHandlerInterface;
41+
42+
final class ExampleMiddleware implements MiddlewareInterface {
43+
44+
public function process(
45+
WriteHandle $writeHandle,
46+
ServerRequestInterface $request,
47+
RequestHandlerInterface $handler,
48+
): ResponseInterface {
49+
return $handler->handle($write, $request);
50+
}
51+
}
52+
```

composer.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "nazg/http-server-request-handler",
3+
"description": "PSR-15 like HTTP Server Request Handler Interface",
4+
"keywords": [
5+
"hhvm",
6+
"hack",
7+
"http-handlers",
8+
"request",
9+
"server",
10+
"middleware"
11+
],
12+
"homepage": "https://github.com/nazg-hack/http-server-request-handler",
13+
"license": [
14+
"MIT"
15+
],
16+
"authors": [
17+
{
18+
"name": "Yuuki Takezawa",
19+
"email": "[email protected]"
20+
}
21+
],
22+
"require": {
23+
"hhvm": ">=3.30.0",
24+
"hhvm/hhvm-autoload": "^1.7",
25+
"hhvm/hsl-experimental": "^3.30.0",
26+
"facebook/hack-http-request-response-interfaces": "^0.1"
27+
},
28+
"require-dev": {
29+
"hhvm/hhast": "^3.30.0"
30+
},
31+
"autoload": {
32+
"psr-4": {
33+
"Nazg\\Http\\Server\\": "src/"
34+
}
35+
},
36+
"minimum-stability": "stable"
37+
}

hh_autoload.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"roots": [
3+
"src/"
4+
],
5+
"devRoots": []
6+
}

hhast-lint.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"roots": [
3+
"src/"
4+
],
5+
"namespaceAliases": {
6+
"HHAST": "Facebook\\HHAST\\Linters"
7+
}
8+
}

src/MiddlewareInterface.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?hh // strict
2+
3+
/**
4+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
7+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
8+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
9+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
10+
* THE SOFTWARE.
11+
*
12+
* This software consists of voluntary contributions made by many individuals
13+
* and is licensed under the MIT license.
14+
*
15+
* Copyright (c) 2018 Yuuki Takezawa
16+
*
17+
*/
18+
namespace Nazg\Http\Server;
19+
20+
use type HH\Lib\Experimental\IO\WriteHandle;
21+
use type Facebook\Experimental\Http\Message\ResponseInterface;
22+
use type Facebook\Experimental\Http\Message\ServerRequestInterface;
23+
24+
/**
25+
* An HTTP middleware component participates in processing an HTTP message,
26+
* either by acting on the request or the response. This interface defines the
27+
* methods required to use the middleware.
28+
*/
29+
interface MiddlewareInterface {
30+
31+
/**
32+
* Process an incoming server request and return a response, optionally delegating
33+
* response creation to a handler.
34+
*
35+
* @param WriteHandle $handler
36+
* @param ServerRequestInterface $request
37+
* @param RequestHandlerInterface $handler
38+
* @return ResponseInterface
39+
*/
40+
public function process(
41+
WriteHandle $writeHandle,
42+
ServerRequestInterface $request,
43+
RequestHandlerInterface $handler
44+
): ResponseInterface;
45+
}

src/RequestHandlerInterface.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?hh // strict
2+
3+
/**
4+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
7+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
8+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
9+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
10+
* THE SOFTWARE.
11+
*
12+
* This software consists of voluntary contributions made by many individuals
13+
* and is licensed under the MIT license.
14+
*
15+
* Copyright (c) 2018 Yuuki Takezawa
16+
*
17+
*/
18+
namespace Nazg\Http\Server;
19+
20+
use type HH\Lib\Experimental\IO\WriteHandle;
21+
use type Facebook\Experimental\Http\Message\ResponseInterface;
22+
use type Facebook\Experimental\Http\Message\ServerRequestInterface;
23+
24+
/**
25+
* An HTTP request handler process a HTTP request and produces an HTTP response.
26+
* This interface defines the methods require to use the request handler.
27+
*/
28+
interface RequestHandlerInterface {
29+
30+
/**
31+
* Handle the request and return a response.
32+
* @param WriteHandle $writeHandle
33+
* @param ServerRequestInterface $request
34+
*
35+
* @return ResponseInterface
36+
*/
37+
public function handle(
38+
WriteHandle $writeHandle,
39+
ServerRequestInterface $request
40+
): ResponseInterface;
41+
}

0 commit comments

Comments
 (0)