Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow PUT command to work with microWebSrv #146

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def __init__(self, socket, httpClient, httpResponse, maxRecvLen, threaded, accep

def _handshake(self, httpResponse) :
try :
key = self._httpCli.GetRequestHeaders().get('Sec-WebSocket-Key', None)
key = self._httpCli.GetRequestHeaders().get('sec-websocket-key', None)
if key :
key += self._handshakeSign
r = sha1(key.encode()).digest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@

class MicroWebSrvRoute :
def __init__(self, route, method, func, routeArgNames, routeRegex) :
self.route = route
self.method = method
self.func = func
self.route = route
self.method = method
self.func = func
self.routeArgNames = routeArgNames
self.routeRegex = routeRegex
self.routeRegex = routeRegex


class MicroWebSrv :
Expand Down Expand Up @@ -305,7 +305,7 @@ def GetMimeTypeFromFilename(self, filename) :
return None

# ----------------------------------------------------------------------------

def GetRouteHandler(self, resUrl, method) :
if self._routeHandlers :
#resUrl = resUrl.upper()
Expand Down Expand Up @@ -366,7 +366,7 @@ def __init__(self, microWebSrv, socket, addr) :
self._headers = { }
self._contentType = None
self._contentLength = 0

self._processRequest()

# ------------------------------------------------------------------------
Expand Down Expand Up @@ -444,27 +444,27 @@ def _parseFirstLine(self, response) :
except :
pass
return False

# ------------------------------------------------------------------------

def _parseHeader(self, response) :
while True :
elements = self._socket.readline().decode().strip().split(':', 1)
if len(elements) == 2 :
self._headers[elements[0].strip()] = elements[1].strip()
self._headers[elements[0].strip().lower()] = elements[1].strip()
elif len(elements) == 1 and len(elements[0]) == 0 :
if self._method == 'POST' :
self._contentType = self._headers.get("Content-Type", None)
self._contentLength = int(self._headers.get("Content-Length", 0))
if self._method == 'POST' or self._method == 'PUT' :
self._contentType = self._headers.get("content-type", None)
self._contentLength = int(self._headers.get("content-length", 0))
return True
else :
return False

# ------------------------------------------------------------------------

def _getConnUpgrade(self) :
if 'upgrade' in self._headers.get('Connection', '').lower() :
return self._headers.get('Upgrade', '').lower()
if 'upgrade' in self._headers.get('connection', '').lower() :
return self._headers.get('upgrade', '').lower()
return None

# ------------------------------------------------------------------------
Expand Down Expand Up @@ -563,7 +563,7 @@ def ReadRequestContentAsJSON(self) :
return loads(self.ReadRequestContent())
except :
return None

# ============================================================================
# ===( Class Response )======================================================
# ============================================================================
Expand Down