Create a Soup's message. Encodes data and adds it to the message as the request body. Args: method: HTTP method of the message. url: Url of the message. data: Request body or form data. headers: HTTP headers of the message.
(
self, method: str, url: str, data: Any = {}, headers: dict = {}, form: bool = False
)
| 44 | return data_glib_bytes |
| 45 | |
| 46 | def create_message( |
| 47 | self, method: str, url: str, data: Any = {}, headers: dict = {}, form: bool = False |
| 48 | ) -> Soup.Message: |
| 49 | """ |
| 50 | Create a Soup's message. |
| 51 | |
| 52 | Encodes data and adds it to the message as the request body. |
| 53 | |
| 54 | Args: |
| 55 | method: HTTP method of the message. |
| 56 | url: Url of the message. |
| 57 | data: Request body or form data. |
| 58 | headers: HTTP headers of the message. |
| 59 | form: If the data should be encoded as ``application/x-www-form-urlencoded``. |
| 60 | |
| 61 | Returns: |
| 62 | The Soup Message for the given parameters. |
| 63 | """ |
| 64 | |
| 65 | if form and data: |
| 66 | form_data = Soup.form_encode_hash(data) |
| 67 | message = Soup.Message.new_from_encoded_form(method, url, form_data) |
| 68 | else: |
| 69 | message = Soup.Message.new(method, url) |
| 70 | |
| 71 | if message: |
| 72 | if data and not form: |
| 73 | data = self.encode_data(data) |
| 74 | message.set_request_body_from_bytes("application/json", data) |
| 75 | if headers: |
| 76 | for name, value in headers.items(): |
| 77 | message.get_request_headers().append(name, value) |
| 78 | if "User-Agent" not in headers: |
| 79 | message.get_request_headers().append("User-Agent", "Dialect App") |
| 80 | |
| 81 | return message # type: ignore |
| 82 | |
| 83 | async def send_and_read(self, message: Soup.Message) -> bytes | None: |
| 84 | """ |
no test coverage detected