
from libmproxy.protocol.http import HTTPRequest
from libmproxy.protocol.tcp import TCPHandler
from libmproxy.protocol import KILL
from libmproxy.script import concurrent


def start(context, argv):
    HTTPRequest._headers_to_strip_off.remove("Connection")
    HTTPRequest._headers_to_strip_off.remove("Upgrade")


def done(context):
    HTTPRequest._headers_to_strip_off.append("Connection")
    HTTPRequest._headers_to_strip_off.append("Upgrade")

@concurrent
def response(context, flow):
    if flow.response.headers.get_first("Connection", None) == "Upgrade":
        # We need to send the response manually now...
        flow.client_conn.send(flow.response.assemble())
        # ...and then delegate to tcp passthrough.
        TCPHandler(flow.live.c, log=False).handle_messages()
        flow.reply(KILL)

from libmproxy.protocol.http import HTTPRequest
from libmproxy.protocol.tcp import TCPHandler
from libmproxy.protocol import KILL
from libmproxy.script import concurrent


def start(context, argv):
    HTTPRequest._headers_to_strip_off.remove("Connection")
    HTTPRequest._headers_to_strip_off.remove("Upgrade")


def done(context):
    HTTPRequest._headers_to_strip_off.append("Connection")
    HTTPRequest._headers_to_strip_off.append("Upgrade")

@concurrent
def response(context, flow):
    value = flow.response.headers.get_first("Connection", None)
    if value and value.upper() == "UPGRADE":
        # We need to send the response manually now...
        flow.client_conn.send(flow.response.assemble())
        # ...and then delegate to tcp passthrough.
        TCPHandler(flow.live.c, log=False).handle_messages()
        flow.reply(KILL)
Make the Websocket's connection header value case-insensitive
Make the Websocket's connection header value case-insensitive

  
  from libmproxy.protocol.http import HTTPRequest
  from libmproxy.protocol.tcp import TCPHandler
  from libmproxy.protocol import KILL
  from libmproxy.script import concurrent
  
  
  def start(context, argv):
      HTTPRequest._headers_to_strip_off.remove("Connection")
      HTTPRequest._headers_to_strip_off.remove("Upgrade")
  
  
  def done(context):
      HTTPRequest._headers_to_strip_off.append("Connection")
      HTTPRequest._headers_to_strip_off.append("Upgrade")
  
  @concurrent
  def response(context, flow):
-     if flow.response.headers.get_first("Connection", None) == "Upgrade":
+     value = flow.response.headers.get_first("Connection", None)
+     if value and value.upper() == "UPGRADE":
          # We need to send the response manually now...
          flow.client_conn.send(flow.response.assemble())
          # ...and then delegate to tcp passthrough.
          TCPHandler(flow.live.c, log=False).handle_messages()
          flow.reply(KILL)
Make the Websocket's connection header value case-insensitive
## Code Before:

from libmproxy.protocol.http import HTTPRequest
from libmproxy.protocol.tcp import TCPHandler
from libmproxy.protocol import KILL
from libmproxy.script import concurrent


def start(context, argv):
    HTTPRequest._headers_to_strip_off.remove("Connection")
    HTTPRequest._headers_to_strip_off.remove("Upgrade")


def done(context):
    HTTPRequest._headers_to_strip_off.append("Connection")
    HTTPRequest._headers_to_strip_off.append("Upgrade")

@concurrent
def response(context, flow):
    if flow.response.headers.get_first("Connection", None) == "Upgrade":
        # We need to send the response manually now...
        flow.client_conn.send(flow.response.assemble())
        # ...and then delegate to tcp passthrough.
        TCPHandler(flow.live.c, log=False).handle_messages()
        flow.reply(KILL)
## Instruction:
Make the Websocket's connection header value case-insensitive
## Code After:

from libmproxy.protocol.http import HTTPRequest
from libmproxy.protocol.tcp import TCPHandler
from libmproxy.protocol import KILL
from libmproxy.script import concurrent


def start(context, argv):
    HTTPRequest._headers_to_strip_off.remove("Connection")
    HTTPRequest._headers_to_strip_off.remove("Upgrade")


def done(context):
    HTTPRequest._headers_to_strip_off.append("Connection")
    HTTPRequest._headers_to_strip_off.append("Upgrade")

@concurrent
def response(context, flow):
    value = flow.response.headers.get_first("Connection", None)
    if value and value.upper() == "UPGRADE":
        # We need to send the response manually now...
        flow.client_conn.send(flow.response.assemble())
        # ...and then delegate to tcp passthrough.
        TCPHandler(flow.live.c, log=False).handle_messages()
        flow.reply(KILL)