-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3515696
commit 5b1d91d
Showing
2 changed files
with
63 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
"""Commands for interacting with HTTP""" | ||
|
||
from mara_page import html, _ | ||
from .. import pipelines | ||
from ..shell import http_request_command | ||
|
||
|
||
class HttpRequest(pipelines.Command): | ||
def __init__(self, url: str, headers: {str: str} = None, method: str = None, body: str = None) -> None: | ||
""" | ||
Executes a HTTP request | ||
Args: | ||
url: The url | ||
headers: The HTTP headers as dict | ||
method: The HTTP method to be used | ||
body: The body string to be used in the HTTP request | ||
""" | ||
super().__init__() | ||
self.url = url | ||
self.headers = headers | ||
self.method = method | ||
self.body = body | ||
|
||
def shell_command(self): | ||
return http_request_command(self.url, self.headers, self.method, self.body) | ||
|
||
def html_doc_items(self) -> [(str, str)]: | ||
return [ | ||
('method', _.tt[self.method or 'GET']), | ||
('url', _.tt[self.url]), | ||
('headers', _.pre[ | ||
'\n'.join([f'{header}: {content}' for header, content in self.headers.items()]) if self.headers else '' | ||
]), | ||
('body', _.pre[self.body or '']), | ||
('command', html.highlight_syntax(self.shell_command(), 'bash')) | ||
] |
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