requestHandlers.py
def post(requestDict, *args):
    """
    The meaning of the Content-Location header in PUT or POST requests is
    undefined; servers are free to ignore it in those cases. (ignored)
    """
    if(not utils.compatCheck(requestDict['requestLine']['httpVersion'])):
        return badRequest(requestDict, '505')
    if('host' not in requestDict['requestHeaders']):
        return badRequest(requestDict, '400')
    requestHeaders = requestDict['requestHeaders']
    config = configparser.ConfigParser()
    config.read('conf/myserver.conf')
    ipaddress = args[1]
    postDataLogPath = os.path.join(config['DEFAULT']['LogDir'], config['DEFAULT']['PostDataLog'])
    dm = datetime.fromtimestamp(mktime(time.gmtime(os.path.getmtime(postDataLogPath))))
    ifmatch = requestHeaders.get('if-match',"*")  
    ifmatchlist = utils.ifmatchparser(ifmatch)
    Etag =  '"{}"'.format(hashlib.md5((utils.rfcDate(dm)).encode()).hexdigest())
    for iftag in ifmatchlist:
        if iftag == "*" or Etag == iftag:
            break
    else:
        return badRequest(requestDict, '412')
    statusCode = None
    responseBody = ''
    with open('media-types/content-type-rev.json','r') as f:
        typeToExt = json.load(f) 
    contentEncoding = requestDict['requestHeaders'].get('content-encoding', '')
    contentEncoding = contentEncoding.split(',')
    contentType = requestDict['requestHeaders'].get('content-type', '')
    contentExt =  typeToExt.get(contentType, '')
    body = requestDict['requestBody']
    try:
        cookie = utils.parsecookie(requestHeaders['cookie'])    
    except:
        cookie = utils.makecookie('/',ipaddress,utils.rfcDate(datetime.utcnow()))   
    #decoding according to content-encoding
    if('content-md5' in requestDict['requestHeaders']):
        checksum = hashlib.md5(body).hexdigest()
        if(checksum != requestDict['requestHeaders']['content-md5']):
            statusCode = '400'
    if(not statusCode):
        for i in contentEncoding:
            i=i.strip()
            if(i == 'gzip' or i == 'x-gzip'):
                body = gzip.decompress(body)
            if(i == 'compress'):
                body = lzw3.decompress(body)
            if(i == 'deflate'):
                body = zlib.decompress(body)
            if(i == 'br'):
                body = brotli.decompress(body)
        #handling according to content-type
        statusCode = "200"
        if(contentExt=="x-www-form-urlencoded"):
            body = body.decode()
            queryDict = parse_qs(body, encoding='utf-8')
            queryWithDate = {utils.logDate(): queryDict}
            try:
                with open(postDataLogPath, "a") as f:
                    json.dump(queryWithDate, f, indent="\t")
                    #log not exactly in json, but avoids reading overhead
                    f.write("\n")
                statusCode = "200"
                responseBody = "Data Logged"
            except PermissionError:
                return badRequest(requestDict, '403')
            except:
                statusCode = "500"
        elif(contentExt=="json"):
            body = body.decode()
            body = json.loads(body)
            queryWithDate = {utils.logDate(): body}
            try:
                with open(postDataLogPath, "a") as f:
                    json.dump(queryWithDate, f, indent="\t")
                    #log not exactly in json, but avoids reading overhead
                    f.write("\n")
                statusCode = "200"
                responseBody = "Data Logged"
            except PermissionError:
                return badRequest(requestDict, '403')
            except:
                statusCode = "500"
        else:
            try:
                queryWithDate = {utils.logDate(): body}
                with open(postDataLogPath, "a") as f:
                    json.dump(queryWithDate, f, indent="\t")
                    f.write("\n")
                statusCode = "200"
                responseBody = "Data Logged"
            except PermissionError:
                return badRequest(requestDict, '403')
            except:
                statusCode = "500"
    if(statusCode == "400"):
        responseDict = badRequest(requestDict, statusCode)
    else:
        responseDict = {
            'statusLine': {'httpVersion':'HTTP/1.1', 'statusCode':statusCode, 'reasonPhrase':utils.givePhrase(statusCode)},
            'responseHeaders': {
                'Connection': 'close',
                'Date': utils.rfcDate(datetime.utcnow()),  
                'Server': utils.getServerInfo()  ,
                'ETag' : Etag        
            },
            'responseBody' : responseBody.encode()
        }
        responseDict['responseHeaders'].__setitem__('Content-Length',str(len(responseDict['responseBody'])))
        for i in cookie.keys():
            responseDict['responseHeaders'].__setitem__('Set-Cookie',i + '=' + cookie[i])
    return responseDict

    The meaning of the Content-Location header in PUT or POST requests is
    undefined; servers are free to ignore it in those cases. (ignored)
    
The meaning of the Content-Location header in PUT or POST requests is
undefined; servers are free to ignore it in those cases. (ignored)
The meaning of the Content - Location header in PUT or POST requests is undefined ; servers are free to ignore it in those cases . ( ignored )
def post(requestDict, *args):
    if(not utils.compatCheck(requestDict['requestLine']['httpVersion'])):
        return badRequest(requestDict, '505')
    if('host' not in requestDict['requestHeaders']):
        return badRequest(requestDict, '400')
    requestHeaders = requestDict['requestHeaders']
    config = configparser.ConfigParser()
    config.read('conf/myserver.conf')
    ipaddress = args[1]
    postDataLogPath = os.path.join(config['DEFAULT']['LogDir'], config['DEFAULT']['PostDataLog'])
    dm = datetime.fromtimestamp(mktime(time.gmtime(os.path.getmtime(postDataLogPath))))
    ifmatch = requestHeaders.get('if-match',"*")  
    ifmatchlist = utils.ifmatchparser(ifmatch)
    Etag =  '"{}"'.format(hashlib.md5((utils.rfcDate(dm)).encode()).hexdigest())
    for iftag in ifmatchlist:
        if iftag == "*" or Etag == iftag:
            break
    else:
        return badRequest(requestDict, '412')
    statusCode = None
    responseBody = ''
    with open('media-types/content-type-rev.json','r') as f:
        typeToExt = json.load(f) 
    contentEncoding = requestDict['requestHeaders'].get('content-encoding', '')
    contentEncoding = contentEncoding.split(',')
    contentType = requestDict['requestHeaders'].get('content-type', '')
    contentExt =  typeToExt.get(contentType, '')
    body = requestDict['requestBody']
    try:
        cookie = utils.parsecookie(requestHeaders['cookie'])    
    except:
        cookie = utils.makecookie('/',ipaddress,utils.rfcDate(datetime.utcnow()))   
    if('content-md5' in requestDict['requestHeaders']):
        checksum = hashlib.md5(body).hexdigest()
        if(checksum != requestDict['requestHeaders']['content-md5']):
            statusCode = '400'
    if(not statusCode):
        for i in contentEncoding:
            i=i.strip()
            if(i == 'gzip' or i == 'x-gzip'):
                body = gzip.decompress(body)
            if(i == 'compress'):
                body = lzw3.decompress(body)
            if(i == 'deflate'):
                body = zlib.decompress(body)
            if(i == 'br'):
                body = brotli.decompress(body)
        statusCode = "200"
        if(contentExt=="x-www-form-urlencoded"):
            body = body.decode()
            queryDict = parse_qs(body, encoding='utf-8')
            queryWithDate = {utils.logDate(): queryDict}
            try:
                with open(postDataLogPath, "a") as f:
                    json.dump(queryWithDate, f, indent="\t")
                    f.write("\n")
                statusCode = "200"
                responseBody = "Data Logged"
            except PermissionError:
                return badRequest(requestDict, '403')
            except:
                statusCode = "500"
        elif(contentExt=="json"):
            body = body.decode()
            body = json.loads(body)
            queryWithDate = {utils.logDate(): body}
            try:
                with open(postDataLogPath, "a") as f:
                    json.dump(queryWithDate, f, indent="\t")
                    f.write("\n")
                statusCode = "200"
                responseBody = "Data Logged"
            except PermissionError:
                return badRequest(requestDict, '403')
            except:
                statusCode = "500"
        else:
            try:
                queryWithDate = {utils.logDate(): body}
                with open(postDataLogPath, "a") as f:
                    json.dump(queryWithDate, f, indent="\t")
                    f.write("\n")
                statusCode = "200"
                responseBody = "Data Logged"
            except PermissionError:
                return badRequest(requestDict, '403')
            except:
                statusCode = "500"
    if(statusCode == "400"):
        responseDict = badRequest(requestDict, statusCode)
    else:
        responseDict = {
            'statusLine': {'httpVersion':'HTTP/1.1', 'statusCode':statusCode, 'reasonPhrase':utils.givePhrase(statusCode)},
            'responseHeaders': {
                'Connection': 'close',
                'Date': utils.rfcDate(datetime.utcnow()),  
                'Server': utils.getServerInfo()  ,
                'ETag' : Etag        
            },
            'responseBody' : responseBody.encode()
        }
        responseDict['responseHeaders'].__setitem__('Content-Length',str(len(responseDict['responseBody'])))
        for i in cookie.keys():
            responseDict['responseHeaders'].__setitem__('Set-Cookie',i + '=' + cookie[i])
    return responseDict
def post ( requestDict , * args ) : if ( not utils . compatCheck ( requestDict [ 'requestLine' ] [ 'httpVersion' ] ) ) : return badRequest ( requestDict , '505' ) if ( 'host' not in requestDict [ 'requestHeaders' ] ) : return badRequest ( requestDict , '400' ) requestHeaders = requestDict [ 'requestHeaders' ] config = configparser . ConfigParser ( ) config . read ( 'conf/myserver.conf' ) ipaddress = args [ 1 ] postDataLogPath = os . path . join ( config [ 'DEFAULT' ] [ 'LogDir' ] , config [ 'DEFAULT' ] [ 'PostDataLog' ] ) dm = datetime . fromtimestamp ( mktime ( time . gmtime ( os . path . getmtime ( postDataLogPath ) ) ) ) ifmatch = requestHeaders . get ( 'if-match' , "*" ) ifmatchlist = utils . ifmatchparser ( ifmatch ) Etag = '"{}"' . format ( hashlib . md5 ( ( utils . rfcDate ( dm ) ) . encode ( ) ) . hexdigest ( ) ) for iftag in ifmatchlist : if iftag == "*" or Etag == iftag : break else : return badRequest ( requestDict , '412' ) statusCode = None responseBody = '' with open ( 'media-types/content-type-rev.json' , 'r' ) as f : typeToExt = json . load ( f ) contentEncoding = requestDict [ 'requestHeaders' ] . get ( 'content-encoding' , '' ) contentEncoding = contentEncoding . split ( ',' ) contentType = requestDict [ 'requestHeaders' ] . get ( 'content-type' , '' ) contentExt = typeToExt . get ( contentType , '' ) body = requestDict [ 'requestBody' ] try : cookie = utils . parsecookie ( requestHeaders [ 'cookie' ] ) except : cookie = utils . makecookie ( '/' , ipaddress , utils . rfcDate ( datetime . utcnow ( ) ) ) if ( 'content-md5' in requestDict [ 'requestHeaders' ] ) : checksum = hashlib . md5 ( body ) . hexdigest ( ) if ( checksum != requestDict [ 'requestHeaders' ] [ 'content-md5' ] ) : statusCode = '400' if ( not statusCode ) : for i in contentEncoding : i = i . strip ( ) if ( i == 'gzip' or i == 'x-gzip' ) : body = gzip . decompress ( body ) if ( i == 'compress' ) : body = lzw3 . decompress ( body ) if ( i == 'deflate' ) : body = zlib . decompress ( body ) if ( i == 'br' ) : body = brotli . decompress ( body ) statusCode = "200" if ( contentExt == "x-www-form-urlencoded" ) : body = body . decode ( ) queryDict = parse_qs ( body , encoding = 'utf-8' ) queryWithDate = { utils . logDate ( ) : queryDict } try : with open ( postDataLogPath , "a" ) as f : json . dump ( queryWithDate , f , indent = "\t" ) f . write ( "\n" ) statusCode = "200" responseBody = "Data Logged" except PermissionError : return badRequest ( requestDict , '403' ) except : statusCode = "500" elif ( contentExt == "json" ) : body = body . decode ( ) body = json . loads ( body ) queryWithDate = { utils . logDate ( ) : body } try : with open ( postDataLogPath , "a" ) as f : json . dump ( queryWithDate , f , indent = "\t" ) f . write ( "\n" ) statusCode = "200" responseBody = "Data Logged" except PermissionError : return badRequest ( requestDict , '403' ) except : statusCode = "500" else : try : queryWithDate = { utils . logDate ( ) : body } with open ( postDataLogPath , "a" ) as f : json . dump ( queryWithDate , f , indent = "\t" ) f . write ( "\n" ) statusCode = "200" responseBody = "Data Logged" except PermissionError : return badRequest ( requestDict , '403' ) except : statusCode = "500" if ( statusCode == "400" ) : responseDict = badRequest ( requestDict , statusCode ) else : responseDict = { 'statusLine' : { 'httpVersion' : 'HTTP/1.1' , 'statusCode' : statusCode , 'reasonPhrase' : utils . givePhrase ( statusCode ) } , 'responseHeaders' : { 'Connection' : 'close' , 'Date' : utils . rfcDate ( datetime . utcnow ( ) ) , 'Server' : utils . getServerInfo ( ) , 'ETag' : Etag } , 'responseBody' : responseBody . encode ( ) } responseDict [ 'responseHeaders' ] . __setitem__ ( 'Content-Length' , str ( len ( responseDict [ 'responseBody' ] ) ) ) for i in cookie . keys ( ) : responseDict [ 'responseHeaders' ] . __setitem__ ( 'Set-Cookie' , i + '=' + cookie [ i ] ) return responseDict
The meaning of the Content-Location header in PUT or POST requests is
undefined; servers are free to ignore it in those cases.
The meaning of the Content - Location header in PUT or POST requests is undefined ; servers are free to ignore it in those cases .
"""
    The meaning of the Content-Location header in PUT or POST requests is
    undefined; servers are free to ignore it in those cases. (ignored)
    """ #decoding according to content-encoding #handling according to content-type #log not exactly in json, but avoids reading overhead #log not exactly in json, but avoids reading overhead
requestDict