| 82 | |
| 83 | |
| 84 | class HTTPHdr: |
| 85 | |
| 86 | def __init__(self, val): |
| 87 | self.impl = val['m_http'] |
| 88 | self.val = val |
| 89 | |
| 90 | def url(self): |
| 91 | return URL(self.val['m_url_cached']) |
| 92 | |
| 93 | def is_request(self): |
| 94 | pol = self.impl['m_polarity'] |
| 95 | return pol == 1 |
| 96 | |
| 97 | def is_response(self): |
| 98 | pol = self.impl['m_polarity'] |
| 99 | return pol == 2 |
| 100 | |
| 101 | def is_valid(self): |
| 102 | if self.impl == 0: |
| 103 | return None |
| 104 | pol = self.impl['m_polarity'] |
| 105 | return pol > 0 |
| 106 | |
| 107 | def method(self): |
| 108 | idx = self.impl['u']['req']['m_method_wks_idx'] |
| 109 | if idx >= 0: |
| 110 | return hdrtoken(idx) |
| 111 | else: |
| 112 | return ats_str(self.impl['u']['req']['m_ptr_method'], self.impl['u']['req']['m_len_method']) |
| 113 | |
| 114 | def status(self): |
| 115 | return self.impl['u']['resp']['m_status'] |
| 116 | |
| 117 | def headers(self): |
| 118 | mime = self.val['m_mime'].dereference() |
| 119 | fblock_ptr = mime['m_first_fblock'].address |
| 120 | while fblock_ptr != 0: |
| 121 | fblock = fblock_ptr.dereference() |
| 122 | slots = fblock['m_field_slots'] |
| 123 | #print("slots type {} address {} size {}".format(slots.type, slots.address, slots.type.sizeof)) |
| 124 | #print("next idx {} len {} next {}".format(fblock['m_freetop'], fblock['m_length'], fblock['m_next'])) |
| 125 | |
| 126 | for slot_idx in range(fblock['m_freetop']): |
| 127 | fld = slots[slot_idx] |
| 128 | wks = fld['m_wks_idx'] |
| 129 | name = wks_or_str(wks, fld['m_ptr_name'], fld['m_len_name']) |
| 130 | yield (name, ats_str(fld['m_ptr_value'], fld['m_len_value'])) |
| 131 | |
| 132 | fblock_ptr = fblock['m_next'] |
| 133 | |
| 134 | def pr(self): |
| 135 | if self.is_valid(): |
| 136 | if self.is_request(): |
| 137 | print("{} {}".format(self.method(), self.url())) |
| 138 | if self.is_response(): |
| 139 | print("status: {}".format(self.status())) |
| 140 | for key, val in self.headers(): |
| 141 | print("{}: {}".format(key, val)) |
no outgoing calls
no test coverage detected