GitHub - xnbox/DeepfakeHTTP: 🟪 DeepfakeHTTP is an HTTP server that uses HTTP dum...
source link: https://github.com/xnbox/DeepfakeHTTP
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
DeepfakeHTTP – Your 100% static dynamic backend
DeepfakeHTTP is an HTTP server that uses HTTP dumps as a source for responses.
Use it for:
- Creating the product POC or demo before even starting out with the backend
- REST, GraphQL, and other APIs prototyping and testing
- Hiding critical enterprise infrastructure behind a simple static facade
- Hacking and fine-tuning HTTP communications on both server and client sides
How it works
- Got client request
- Search dump entries (request-response pairs) for appropriate entry by matching all specified request entry parts: method, path, headers, body
- If entry is found, the server sends corresponded response to the client
- If entry is not found, server search dump entries for response with status
400
(Bad request). - If found, send it to the client
- If not found, sends status
400
with no body.
Try it
- Copy-paste the content of the dump example to the file
MyDump.txt
- Start the DeepfakeHTTP server from command line:
java -jar df.jar MyDump.txt
- Use a browser to check whether DeepfakeHTTP is running:
http://localhost:8080/form.html
Dump example
# Comments are welcome! :)
GET /form.html HTTP/1.1
# Fake HTML file :)
HTTP/1.1 200 OK
<!DOCTYPE html>
<html lang="en">
<body>
<form action="/add_user.php" method="POST">
<label for="fname">First name:</label><input type="text" name="fname"><br><br>
<label for="lname">Last name: </label><input type="text" name="lname"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
POST /add_user.php HTTP/1.1
Content-Type: application/x-www-form-urlencoded
# Fake PHP file :)
HTTP/1.1 200 OK
Content-Type: text/html
X-Body-Type: text/template
<!DOCTYPE html>
<html lang="en">
<body>
<h1>Hello, ${fname[0]} ${lname[0]}!</h1>
</body>
</html>
For more examples see here.
Features
- No dependencies
- No installation
- No configuration files
- Single-file executable
- Fully asynchronous
- ETag optimization
... also supports:
- all HTTP methods
- multi-line and multi-value headers
- wildcards (
*
and?
with escape/
) in request path and header values - templates in response body
- response body fetching from external sources like URLs, local files, and data URI
- per entry user-defined request and response delays (lags)
Prerequisites
- Java 15 or above
Command Line Interface (CLI)
java -jar df.jar [options] [dump1.txt] [dump2.txt] ...
Options:
--help print help message
--port TCP port number, default: 8080
--no-listen disable listening on dump(s) changes
--no-etag disable ETag optimization
Optional response headers
(will not be sent to clients)
Header DescriptionX-Body-Type
Tells the server what the content type (media type) of the returned content actually is. Value of this header has same rules as value of standard HTTP Content-Type
header.
This header is useful when you want to use template or binary data as a response body.
Examples:# Response body is a character data.
# No 'X-Body-Type' header needed.
HTTP/1.1 200 OK
Content-Type: application/json
{"id": 5, "name": "John Doe"}
# Get response body from remote server
# Body type is 'text/uri-list' (See: RFC 2483)
HTTP/1.1 200 OK
Content-Type: application/json
X-Body-Type: text/uri-list
http://example.com/api/car/1234
# Get response body from file:
# Body type is 'text/uri-list' (See: RFC 2483)
HTTP/1.1 200 OK
Content-Type: image/jpeg
X-Body-Type: text/uri-list
file:///home/john/photo.jpeg
# Get response body from data URI:
# Body type is 'text/uri-list' (See: RFC 2483)
HTTP/1.1 200 OK
Content-Type: image/gif
X-Body-Type: text/uri-list
data:image/gif;base64,R0lGODlhAQABAIAAAP...
# Get response body from template
# Body type is 'text/template'. Useful for forms processing.
HTTP/1.1 200 OK
Content-Type: text/html
X-Body-Type: text/template
<!DOCTYPE html>
<html lang="en">
<body>
<h1>Hello, ${fname[0]} ${lname[0]}!</h1>
</body>
</html>
X-Request-Delay
Request delay (in milliseconds).
Example:# Two seconds request delay.
HTTP/1.1 200 OK
X-Request-Delay: 2000
{"id": 5, "name": "John Doe"}
X-Response-Delay
Response delay (in milliseconds).
Example:# Two seconds response delay.
HTTP/1.1 200 OK
X-Response-Delay: 2000
{"id": 5, "name": "John Doe"}
Download
Latest release: df-1.0.2.jarLicense
The DeepfakeHTTP is released under MIT license.APPENDIX
Dump examples
Example 1.
# Comments are welcome! :)
# Please don't miss a single carriage return between headers and body!
#
# First request-response entry
#
# Client request
GET /api/customer/5 HTTP/1.1
Accept-Language: ru;*
# Server response
HTTP/1.1 200 OK
Content-Type: application/json
{
"id": 5,
"name": "Джон Доу"
}
#
# Second request-response entry
#
# Client request
GET /api/customer/5 HTTP/1.1
# Server response
HTTP/1.1 200 OK
Content-Type: application/json
{
"id": 5,
"name": "John Doe"
}
Example 2.
#
# Work with HTML forms (1)
#
GET /form.html HTTP/1.1
HTTP/1.1 200 OK
<!DOCTYPE html>
<html lang="en">
<body>
<form action="/action_page.php" method="POST">
<label for="fname">First name:</label><input type="text" name="fname"><br><br>
<label for="lname">Last name: </label><input type="text" name="lname"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
POST /action_page.php HTTP/1.1
Content-Type: application/x-www-form-urlencoded
HTTP/1.1 200 OK
Content-Type: text/html
X-Body-Type: text/template
<!DOCTYPE html>
<html lang="en">
<body>
<h1>Hello, ${fname[0]} ${lname[0]}!</h1>
</body>
</html>
Example 3.
#
# Work with HTML forms (2)
#
GET /form.html HTTP/1.1
HTTP/1.1 200 OK
<!DOCTYPE html>
<html lang="en">
<body>
<form action="/action_page.php" method="POST">
<label for="fname">First name:</label><input type="text" name="fname"><br><br>
<label for="lname">Last name: </label><input type="text" name="lname"><br><br>
<p>Only first name 'John' and last name 'Doe' are supported.<br>
Expected output is: Hello, John Doe!,<br>
or HTTP status 400 Bad request if first name is not 'John' or last name is not 'Doe'.
</p><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
POST /action_page.php HTTP/1.1
Content-Type: application/x-www-form-urlencoded
fname=John&lname=Doe
HTTP/1.1 200 OK
Content-Type: text/html
X-Body-Type: text/template
<!DOCTYPE html>
<body>
<h1>Hello, ${fname[0]} ${lname[0]}!</h1>
</body>
</html>
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK