def get_headers_from_request(req):
 headers = getattr(req, 'META', {})
 if headers:
  headers = {'-'.join([part.capitalize() for part in k.split('_')]).replace('Http-', ''): v for (k, v) in headers.items()}
  remote_addr = (headers.get('X-Forwarded-For') or headers.get('Remote-Addr'))
  headers['Remote-Addr'] = (remote_addr.split(',')[0].strip() if remote_addr else None)
 else:
  headers = getattr(req, 'headers', {})
  headers = {k: v for (k, v) in headers.items()}
  headers['Remote-Addr'] = req.remote_addr
 return headers

def get_headers_from_request ( req ) : headers = getattr ( req , 'META' , { } ) if headers : headers = { '-' . join ( [ part . capitalize ( ) for part in k . split ( '_' ) ] ) . replace ( 'Http-' , '' ) : v for ( k , v ) in headers . items ( ) } remote_addr = ( headers . get ( 'X-Forwarded-For' ) or headers . get ( 'Remote-Addr' ) ) headers [ 'Remote-Addr' ] = ( remote_addr . split ( ',' ) [ 0 ] . strip ( ) if remote_addr else None ) else : headers = getattr ( req , 'headers' , { } ) headers = { k : v for ( k , v ) in headers . items ( ) } headers [ 'Remote-Addr' ] = req . remote_addr return headers
get and normalize drf and flask request headers .