Skip to content

Commit

Permalink
remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
amyangfei committed Sep 12, 2022
1 parent 03d60ff commit eae0079
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions gor/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import datetime
import traceback
from urllib.parse import quote_plus, urlparse, parse_qs
from typing import Union, Dict
from typing import Dict


def gor_hex_data(data):
Expand Down Expand Up @@ -115,14 +115,12 @@ def http_status(self, payload: bytes) -> str:
def set_http_status(self, payload: bytes, new_status: str) -> bytes:
return self.set_http_path(payload, new_status)

def http_headers(self, payload: Union[bytes, str]) -> Dict[str, str]:
def http_headers(self, payload: bytes) -> Dict[str, str]:
"""
Parse the payload and return http headers in a map
:param payload: the http payload to inspect
:return: a map mapping from key to value of each http header item
"""
if isinstance(payload, str):
payload = payload.encode()
start_index = payload.index(b"\r\n")
end_index = payload.index(b"\r\n\r\n")
if end_index == -1:
Expand All @@ -135,16 +133,14 @@ def http_headers(self, payload: Union[bytes, str]) -> Dict[str, str]:
headers[key] = value
return headers

def http_header(self, payload: Union[bytes, str], name: str) -> Dict[str, str]:
def http_header(self, payload: bytes, name: str) -> Dict[str, str]:
current_line = 0
idx = 0
header = {
'start': -1,
'end': -1,
'value_start': -1,
}
if isinstance(payload, str):
payload = payload.encode()
name = name.encode()
while idx < len(payload):
c = payload[idx]
Expand Down Expand Up @@ -175,19 +171,15 @@ def http_header(self, payload: Union[bytes, str], name: str) -> Dict[str, str]:
idx += 1
return None

def set_http_header(self, payload: Union[bytes, str], name: str, value: str) -> bytes:
if isinstance(payload, str):
payload = payload.encode()
def set_http_header(self, payload: bytes, name: str, value: str) -> bytes:
header = self.http_header(payload, name)
if header is None:
header_start = payload.index(b'\n') + 1
return payload[:header_start] + name.encode() + b': ' + value.encode() + b'\r\n' + payload[header_start:]
else:
return payload[:header['value_start']] + b' ' + value.encode() + b'\r\n' + payload[header['end']:]

def delete_http_header(self, payload: Union[bytes, str], name: str) -> bytes:
if isinstance(payload, str):
payload = payload.encode()
def delete_http_header(self, payload: bytes, name: str) -> bytes:
header = self.http_header(payload, name)
if header is None:
return payload
Expand Down

0 comments on commit eae0079

Please sign in to comment.