-
Notifications
You must be signed in to change notification settings - Fork 521
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a feature provided by cURL that allows sending requests to a web server via a Unix Domain Socket. Some use cases include: * Querying docker API * Running a web server w/o opening a TCP port for security and/or performance reasons https://curl.se/docs/manpage.html#--unix-socket
- Loading branch information
Showing
42 changed files
with
186 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
name: unix_socket | ||
long: unix-socket | ||
value: <path> | ||
help: (HTTP) Connect through this Unix domain socket, instead of using the network | ||
--- | ||
(HTTP) Connect through this Unix domain socket, instead of using the network. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
error: HTTP connection | ||
--> tests_ok/unix_socket.hurl:1:5 | ||
| | ||
1 | GET http://example/hello | ||
| ^^^^^^^^^^^^^^^^^^^^ (7) ~~~ | ||
| | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Set-StrictMode -Version latest | ||
|
||
# The python test server for testing Unix Domain Sockets | ||
# (../unix_socket/server.py) does not currently support AF_UNIX on Windows. | ||
# See https://github.com/python/cpython/issues/77589 | ||
# Skip for now until this can be easily tested. | ||
$ErrorActionPreference = 'Continue' | ||
exit 255 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
set -Eeuo pipefail | ||
hurl --unix-socket /unknown tests_ok/unix_socket.hurl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
curl --unix-socket 'build/unix_socket.sock' 'http://example/hello' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
GET http://example/hello | ||
HTTP 200 | ||
[Asserts] | ||
`Hello World!` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello World! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Set-StrictMode -Version latest | ||
|
||
# The python test server for testing Unix Domain Sockets | ||
# (../unix_socket/server.py) does not currently support AF_UNIX on Windows. | ||
# See https://github.com/python/cpython/issues/77589 | ||
# Skip for now until this can be easily tested. | ||
$ErrorActionPreference = 'Continue' | ||
exit 255 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
set -Eeuo pipefail | ||
hurl --unix-socket build/unix_socket.sock --verbose tests_ok/unix_socket.hurl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env python3 | ||
from os import path, unlink | ||
from socket import socket, AF_UNIX | ||
from flask import Flask | ||
|
||
app = Flask("Unix Domain Sockets Server") | ||
|
||
|
||
@app.route("/hello") | ||
def hello(): | ||
return "Hello World!" | ||
|
||
|
||
def main(): | ||
sock = socket(AF_UNIX) | ||
socket_path = "build/unix_socket.sock" | ||
|
||
try: | ||
unlink(socket_path) | ||
except OSError: | ||
if path.exists(socket_path): | ||
raise | ||
|
||
sock.bind(socket_path) | ||
|
||
try: | ||
app.run(host="unix://" + socket_path) | ||
finally: | ||
unlink(socket_path) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<pre><code class="language-hurl"><span class="hurl-entry"><span class="request"><span class="line"></span><span class="comment"># Go through a Unix Domain Socket</span> | ||
<span class="line"></span><span class="comment"># Requests will be sent to the Unix Domain Socket instead of over the network</span> | ||
<span class="line"><span class="method">GET</span> <span class="url">http://example/hello</span></span> | ||
<span class="line"><span class="section-header">[Options]</span></span> | ||
<span class="line"><span class="string">unix-socket</span>: <span class="string">build/unix_socket.sock</span></span> | ||
</span><span class="response"><span class="line"><span class="version">HTTP</span> <span class="number">200</span></span> | ||
<span class="line"><span class="section-header">[Asserts]</span></span> | ||
<span class="line"><span class="string">`Hello World!`</span></span> | ||
</span></span></code></pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Go through a Unix Domain Socket | ||
# Requests will be sent to the Unix Domain Socket instead of over the network | ||
GET http://example/hello | ||
[Options] | ||
unix-socket: build/unix_socket.sock | ||
HTTP 200 | ||
[Asserts] | ||
`Hello World!` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"entries":[{"request":{"method":"GET","url":"http://example/hello","options":[{"name":"unix-socket","value":"build/unix_socket.sock"}]},"response":{"status":200,"body":{"type":"text","value":"Hello World!"}}}]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.