Пример #1
0
import urllib3
import logging
import re
import socket
import random
import queue
import socketserver
import http.server
from urllib.parse import urlsplit
from time import time, sleep
from _thread import start_new_thread


logger = logging.getLogger('RangeFetch')

fake_headers = _fake_headers.copy()
# Set 'keep-alive'
fake_headers['Connection'] = 'keep-alive'
del fake_headers['Accept-Encoding']

class LocalTCPServer(socketserver.ThreadingTCPServer):

    request_queue_size = 2
    serving = False

    def server_bind(self):
        sock = self.socket
        sock.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, True)
        self.RequestHandlerClass.bufsize = sock.getsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF)
        super().server_bind()
        ip, port = self.server_address
Пример #2
0
from logging import getLogger
from ykdl.compact import (
    Queue, thread, urlsplit,
    BaseHTTPRequestHandler, SocketServer
    )
from ykdl.util.html import fake_headers as _fake_headers

import urllib3
import re
import socket
from time import time, sleep

logger = getLogger('RangeFetch')

fake_headers = _fake_headers.copy()
# Set 'keep-alive'
fake_headers['Connection'] = 'keep-alive'
del fake_headers['Accept-Encoding']

class LocalTCPServer(SocketServer.ThreadingTCPServer):

    request_queue_size = 2
    allow_reuse_address = True

    def server_bind(self):
        sock = self.socket
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        sock.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, True)
        self.RequestHandlerClass.bufsize = sock.getsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF)
        SocketServer.TCPServer.server_bind(self)