Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit a67d917

Browse files
committed
Change permissions
1 parent ae17519 commit a67d917

31 files changed

+79
-79
lines changed

.github/workflows/autotest.yml

100644100755
File mode changed.

LICENSE

100644100755
File mode changed.

README.md

100644100755
File mode changed.

__init__.py

100644100755
File mode changed.

__pycache__/client.cpython-310.pyc

2.66 KB
Binary file not shown.

__pycache__/client2.cpython-310.pyc

2.66 KB
Binary file not shown.

client.py

100644100755
File mode changed.

env.sh

100644100755
File mode changed.

interface.py

100644100755
File mode changed.

main.py

100644100755
Lines changed: 79 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,80 @@
1-
import argparse
2-
import json
3-
from client import HTTPClient
4-
5-
def parse_headers(header_string):
6-
"""Parse headers from a JSON string into a dictionary."""
7-
if not header_string:
8-
return {}
9-
try:
10-
headers = json.loads(header_string)
11-
if not isinstance(headers, dict):
12-
raise ValueError("Headers must be a JSON object.")
13-
return headers
14-
except json.JSONDecodeError:
15-
raise ValueError("Invalid JSON format for headers.")
16-
17-
def main():
18-
# Create the HTTP client
19-
client = HTTPClient()
20-
21-
# Set up the argument parser
22-
parser = argparse.ArgumentParser(description="HTTP Client for making requests from the command line.", add_help=False)
23-
24-
# Add arguments for HTTP method, URL, headers, and data
25-
parser.add_argument("-m", "--method", type=str, required=True, help="HTTP method (GET, POST, HEAD, DELETE, PATCH, PUT)")
26-
parser.add_argument("-u", "--url", type=str, required=True, help="URL to make the request to")
27-
parser.add_argument("-h", "--headers", type=str, help="Request headers as a JSON string (e.g., '{\"User-Agent\": \"device\"}')", default="{}")
28-
parser.add_argument("-d", "--data", type=str, help="Request body data", default=None)
29-
30-
# Parse the arguments
31-
args = parser.parse_args()
32-
33-
# Parse headers from JSON string
34-
try:
35-
headers = parse_headers(args.headers)
36-
except ValueError as e:
37-
print(f"Error parsing headers: {e}")
38-
return
39-
40-
# Perform the HTTP request
41-
try:
42-
# Handle HEAD request
43-
if args.method.upper() == "HEAD":
44-
if args.data:
45-
print("Error: HEAD requests cannot include a body.")
46-
return
47-
status_code, response_body = client.head(args.url, headers=headers)
48-
49-
# Handle DELETE request
50-
elif args.method.upper() == "DELETE":
51-
status_code, response_body = client.delete(args.url, body=args.data, headers=headers)
52-
53-
# Handle PATCH request
54-
elif args.method.upper() == "PATCH":
55-
status_code, response_body = client.patch(args.url, body=args.data, headers=headers)
56-
57-
# Handle PUT request
58-
elif args.method.upper() == "PUT":
59-
status_code, response_body = client.put(args.url, body=args.data, headers=headers)
60-
61-
# Handle other HTTP methods (e.g., GET, POST)
62-
else:
63-
status_code, response_body = client.http_request(
64-
method=args.method.upper(),
65-
url=args.url,
66-
body=args.data,
67-
headers=headers
68-
)
69-
70-
# Display the response
71-
print(f"Status Code: {status_code}")
72-
print("Response Body:")
73-
print(response_body)
74-
75-
except Exception as e:
76-
# Handle any exceptions that occur during the request
77-
print(f"Error: {e}")
78-
79-
if __name__ == "__main__":
1+
import argparse
2+
import json
3+
from client import HTTPClient
4+
5+
def parse_headers(header_string):
6+
"""Parse headers from a JSON string into a dictionary."""
7+
if not header_string:
8+
return {}
9+
try:
10+
headers = json.loads(header_string)
11+
if not isinstance(headers, dict):
12+
raise ValueError("Headers must be a JSON object.")
13+
return headers
14+
except json.JSONDecodeError:
15+
raise ValueError("Invalid JSON format for headers.")
16+
17+
def main():
18+
# Create the HTTP client
19+
client = HTTPClient()
20+
21+
# Set up the argument parser
22+
parser = argparse.ArgumentParser(description="HTTP Client for making requests from the command line.", add_help=False)
23+
24+
# Add arguments for HTTP method, URL, headers, and data
25+
parser.add_argument("-m", "--method", type=str, required=True, help="HTTP method (GET, POST, HEAD, DELETE, PATCH, PUT)")
26+
parser.add_argument("-u", "--url", type=str, required=True, help="URL to make the request to")
27+
parser.add_argument("-h", "--headers", type=str, help="Request headers as a JSON string (e.g., '{\"User-Agent\": \"device\"}')", default="{}")
28+
parser.add_argument("-d", "--data", type=str, help="Request body data", default=None)
29+
30+
# Parse the arguments
31+
args = parser.parse_args()
32+
33+
# Parse headers from JSON string
34+
try:
35+
headers = parse_headers(args.headers)
36+
except ValueError as e:
37+
print(f"Error parsing headers: {e}")
38+
return
39+
40+
# Perform the HTTP request
41+
try:
42+
# Handle HEAD request
43+
if args.method.upper() == "HEAD":
44+
if args.data:
45+
print("Error: HEAD requests cannot include a body.")
46+
return
47+
status_code, response_body = client.head(args.url, headers=headers)
48+
49+
# Handle DELETE request
50+
elif args.method.upper() == "DELETE":
51+
status_code, response_body = client.delete(args.url, body=args.data, headers=headers)
52+
53+
# Handle PATCH request
54+
elif args.method.upper() == "PATCH":
55+
status_code, response_body = client.patch(args.url, body=args.data, headers=headers)
56+
57+
# Handle PUT request
58+
elif args.method.upper() == "PUT":
59+
status_code, response_body = client.put(args.url, body=args.data, headers=headers)
60+
61+
# Handle other HTTP methods (e.g., GET, POST)
62+
else:
63+
status_code, response_body = client.http_request(
64+
method=args.method.upper(),
65+
url=args.url,
66+
body=args.data,
67+
headers=headers
68+
)
69+
70+
# Display the response
71+
print(f"Status Code: {status_code}")
72+
print("Response Body:")
73+
print(response_body)
74+
75+
except Exception as e:
76+
# Handle any exceptions that occur during the request
77+
print(f"Error: {e}")
78+
79+
if __name__ == "__main__":
8080
main()

request_handler.py

100644100755
File mode changed.

run.sh

100644100755
File mode changed.

tcp_server.py

100644100755
File mode changed.

tests/ftp/dist/ftpserver

100644100755
File mode changed.

tests/ftp/files/2.txt

100644100755
File mode changed.

tests/ftp/files/directory/1.txt

100644100755
File mode changed.

tests/ftp/install.sh

100644100755
File mode changed.

tests/ftp/run.sh

100644100755
File mode changed.

tests/ftp/tester.py

100644100755
File mode changed.

tests/http/install.sh

100644100755
File mode changed.

tests/http/run.sh

100644100755
File mode changed.

tests/http/tests.py

100644100755
File mode changed.

tests/irc/dist/server

100644100755
File mode changed.

tests/irc/exec.sh

100644100755
File mode changed.

tests/irc/install.sh

100644100755
File mode changed.

tests/irc/run.sh

100644100755
File mode changed.

tests/irc/tester.py

100644100755
File mode changed.

tests/setup_and_run.sh

100644100755
File mode changed.

tests/smtp/install.sh

100644100755
File mode changed.

tests/smtp/run.sh

100644100755
File mode changed.

tests/smtp/tests.py

100644100755
File mode changed.

0 commit comments

Comments
 (0)