Skip to content

intel

dandy.http.intelligence.intel

HttpResponseIntel

Bases: BaseIntel

status_code instance-attribute

response_phrase = None class-attribute instance-attribute

text = None class-attribute instance-attribute

json_data = None class-attribute instance-attribute

json_str property

from_httpx_response classmethod

Source code in dandy/http/intelligence/intel.py
@classmethod
def from_httpx_response(cls, httpx_response: httpx.Response) -> Self:
    try:
        json_data = httpx_response.json()
    except ValueError:
        json_data = {}

    return HttpResponseIntel(
        status_code=httpx_response.status_code,
        response_phrase=httpx_response.reason_phrase,
        text=httpx_response.text,
        json_data=json_data
    )

HttpRequestIntel

Bases: BaseIntel

method instance-attribute

url instance-attribute

params = None class-attribute instance-attribute

headers = {'Content-Type': 'text/html'} class-attribute instance-attribute

cookies = None class-attribute instance-attribute

content = None class-attribute instance-attribute

data = None class-attribute instance-attribute

files = None class-attribute instance-attribute

json_data = None class-attribute instance-attribute

stream = None class-attribute instance-attribute

bearer_token = None class-attribute instance-attribute

model_post_init

Source code in dandy/http/intelligence/intel.py
def model_post_init(self, __context: Any):
    self.generate_headers()

as_httpx_request

Source code in dandy/http/intelligence/intel.py
def as_httpx_request(self) -> httpx.Request:
    if isinstance(self.url, Url):
        self.url = self.url.to_str()

    return httpx.Request(
        method=self.method,
        url=self.url,
        params=self.params,
        headers=self.headers,
        cookies=self.cookies,
        content=self.content,
        data=self.data,
        files=self.files,
        json=self.json_data,
        stream=self.stream,
    )

generate_headers

Source code in dandy/http/intelligence/intel.py
def generate_headers(self):
    if self.bearer_token is not None:
        if self.headers is None:
            self.headers = {}

        encoded_bearer_token = b64encode(f"Bearer:{self.bearer_token}".encode()).decode()

        self.headers['Authorization'] = f'Basic {encoded_bearer_token}'