MCPcopy Create free account
hub / github.com/websocket-client/websocket-client / read_headers

Function read_headers

websocket/_http.py:378–411  ·  view source on GitHub ↗
(sock: socket.socket)

Source from the content-addressed store, hash-verified

376
377
378def read_headers(sock: socket.socket) -> tuple:
379 status = None
380 status_message = None
381 headers: dict = {}
382 trace("--- response header ---")
383
384 while True:
385 line = recv_line(sock)
386 line = line.decode("utf-8").strip()
387 if not line:
388 break
389 trace(line)
390 if not status:
391 status_info = line.split(" ", 2)
392 status = int(status_info[1])
393 if len(status_info) > 2:
394 status_message = status_info[2]
395 else:
396 kv = line.split(":", 1)
397 if len(kv) != 2:
398 raise WebSocketException("Invalid header")
399 key, value = kv
400 if key.lower() == "set-cookie" and headers.get("set-cookie"):
401 existing_cookie = headers.get("set-cookie")
402 if existing_cookie is not None:
403 headers["set-cookie"] = existing_cookie + "; " + value.strip()
404 else:
405 headers["set-cookie"] = value.strip()
406 else:
407 headers[key.lower()] = value.strip()
408
409 trace("-----------------------")
410
411 return status, headers, status_message

Callers 4

test_read_headerMethod · 0.90
test_read_headerMethod · 0.90
_tunnelFunction · 0.85
_get_resp_headersFunction · 0.85

Calls 4

traceFunction · 0.85
recv_lineFunction · 0.85
WebSocketExceptionClass · 0.85
getMethod · 0.80

Tested by 2

test_read_headerMethod · 0.72
test_read_headerMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…