import socket, sys

if len(sys.argv) != 6:
  print('Wrong number of arguments. Usage: ./21-ct-clean-up-nc.py <localport> <timeout> <remote-address> <remote-port> <HTTP path>')

localport = int(sys.argv[1])
timeout = int(sys.argv[2])
serverAddr = sys.argv[3]
serverPort = int(sys.argv[4])
httpPath = sys.argv[5]

if ":" not in serverAddr:
  clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  host = serverAddr
else:
  clientsocket = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
  host = "["+serverAddr+"]"

clientsocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
clientsocket.bind(('', localport))
clientsocket.settimeout(timeout)
clientsocket.connect((serverAddr, serverPort))
clientsocket.send('GET '+httpPath+' HTTP/1.0\r\nHost: '+host+
                  '\r\nUser-Agent: curl/7.38.0\r\nAccept: */*\r\n\r\n')

data = clientsocket.recv(4096)
print(data)

import socket, sys

if len(sys.argv) != 6:
  print('Wrong number of arguments. Usage: ./21-ct-clean-up-nc.py <localport> <timeout> <remote-address> <remote-port> <HTTP path>')

localport = int(sys.argv[1])
timeout = int(sys.argv[2])
serverAddr = sys.argv[3]
serverPort = int(sys.argv[4])
httpPath = sys.argv[5]

if ":" not in serverAddr:
  clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  host = serverAddr
else:
  clientsocket = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
  host = "["+serverAddr+"]"

clientsocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
clientsocket.bind(('', localport))
clientsocket.settimeout(timeout)
clientsocket.connect((serverAddr, serverPort))
clientsocket.send('GET '+httpPath+' HTTP/1.1\r\nHost: '+host+
                  '\r\nConnection: close\r\nUser-Agent: curl/7.38.0\r\nAccept: */*\r\n\r\n')

data = clientsocket.recv(4096)
print(data)

Use HTTP 1.1 instead of HTTP 1.0
tests: Use HTTP 1.1 instead of HTTP 1.0

Envoy does not support HTTP 1.0, so use HTTP 1.1 instead.

Signed-off-by: Jarno Rajahalme <0f1ab0ac7dffd9db21aa539af2fd4bb04abc3ad4@covalent.io>

  import socket, sys
  
  if len(sys.argv) != 6:
    print('Wrong number of arguments. Usage: ./21-ct-clean-up-nc.py <localport> <timeout> <remote-address> <remote-port> <HTTP path>')
  
  localport = int(sys.argv[1])
  timeout = int(sys.argv[2])
  serverAddr = sys.argv[3]
  serverPort = int(sys.argv[4])
  httpPath = sys.argv[5]
  
  if ":" not in serverAddr:
    clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    host = serverAddr
  else:
    clientsocket = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
    host = "["+serverAddr+"]"
  
  clientsocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  clientsocket.bind(('', localport))
  clientsocket.settimeout(timeout)
  clientsocket.connect((serverAddr, serverPort))
- clientsocket.send('GET '+httpPath+' HTTP/1.0\r\nHost: '+host+
+ clientsocket.send('GET '+httpPath+' HTTP/1.1\r\nHost: '+host+
-                   '\r\nUser-Agent: curl/7.38.0\r\nAccept: */*\r\n\r\n')
+                   '\r\nConnection: close\r\nUser-Agent: curl/7.38.0\r\nAccept: */*\r\n\r\n')
  
  data = clientsocket.recv(4096)
  print(data)
  
Use HTTP 1.1 instead of HTTP 1.0
## Code Before:
import socket, sys

if len(sys.argv) != 6:
  print('Wrong number of arguments. Usage: ./21-ct-clean-up-nc.py <localport> <timeout> <remote-address> <remote-port> <HTTP path>')

localport = int(sys.argv[1])
timeout = int(sys.argv[2])
serverAddr = sys.argv[3]
serverPort = int(sys.argv[4])
httpPath = sys.argv[5]

if ":" not in serverAddr:
  clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  host = serverAddr
else:
  clientsocket = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
  host = "["+serverAddr+"]"

clientsocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
clientsocket.bind(('', localport))
clientsocket.settimeout(timeout)
clientsocket.connect((serverAddr, serverPort))
clientsocket.send('GET '+httpPath+' HTTP/1.0\r\nHost: '+host+
                  '\r\nUser-Agent: curl/7.38.0\r\nAccept: */*\r\n\r\n')

data = clientsocket.recv(4096)
print(data)

## Instruction:
Use HTTP 1.1 instead of HTTP 1.0
## Code After:
import socket, sys

if len(sys.argv) != 6:
  print('Wrong number of arguments. Usage: ./21-ct-clean-up-nc.py <localport> <timeout> <remote-address> <remote-port> <HTTP path>')

localport = int(sys.argv[1])
timeout = int(sys.argv[2])
serverAddr = sys.argv[3]
serverPort = int(sys.argv[4])
httpPath = sys.argv[5]

if ":" not in serverAddr:
  clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  host = serverAddr
else:
  clientsocket = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
  host = "["+serverAddr+"]"

clientsocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
clientsocket.bind(('', localport))
clientsocket.settimeout(timeout)
clientsocket.connect((serverAddr, serverPort))
clientsocket.send('GET '+httpPath+' HTTP/1.1\r\nHost: '+host+
                  '\r\nConnection: close\r\nUser-Agent: curl/7.38.0\r\nAccept: */*\r\n\r\n')

data = clientsocket.recv(4096)
print(data)
