<commit_before>"""CherryPy core request/response handling."""

import Cookie
import os
import sys
import types

import cherrypy
from cherrypy import _cputil, _cpcgifs, _cpwsgiserver
from cherrypy.filters import applyFilters
from cherrypy.lib import cptools, httptools


class Request(object):
    """An HTTP request."""
    
    def __init__(self, remoteAddr, remotePort, remoteHost, scheme="http"):
        """Populate a new Request object.
        
        remoteAddr should be the client IP address
        remotePort should be the client Port
        remoteHost should be string of the client's IP address.
        scheme should be a string, either "http" or "https".
        """
        self.remoteAddr = remoteAddr
        self.remotePort = remotePort
        self.remoteHost = remoteHost
        self.scheme = scheme
    
    def run(self, requestLine, headers, rfile):
        """Process the Request.
        
        requestLine should be of the form "GET /path HTTP/1.0".
        headers should be a list of (name, value) tuples.
        rfile should be a file-like object containing the HTTP request
            entity.
        
        When run() is done, the returned object should have 3 attributes:
          status, e.g. "200 OK"
          headers, a list of (name, value) tuples
          body, an iterable yielding strings
        
        Consumer code (HTTP servers) should then access these response
        attributes to build the outbound stream.
        
        """
        if cherrypy.profiler:
            cherrypy.profiler.run(self._run, requestLine, headers, rfile)
        else:
            self._run(requestLine, headers, rfile)
        return cherrypy.response
    
    def _run(self, requestLine, headers, rfile):
        
        try:
            self.headers = headers
            self.headerMap = httptools.HeaderMap()
            self.simpleCookie = Cookie.SimpleCookie()
            self.rfile = rfile
            
            # This has to be done very early in the request process,
            # because request.objectPath is used for config lookups
            # right away.
            self.processRequestLine(requestLine)
            <commit_msg>added support for OPTIONS * request<commit_after>"""CherryPy core request/response handling."""

import Cookie
import os
import sys
import types

import cherrypy
from cherrypy import _cputil, _cpcgifs, _cpwsgiserver
from cherrypy.filters import applyFilters
from cherrypy.lib import cptools, httptools


class Request(object):
    """An HTTP request."""
    
    def __init__(self, remoteAddr, remotePort, remoteHost, scheme="http"):
        """Populate a new Request object.
        
        remoteAddr should be the client IP address
        remotePort should be the client Port
        remoteHost should be string of the client's IP address.
        scheme should be a string, either "http" or "https".
        """
        self.remoteAddr = remoteAddr
        self.remotePort = remotePort
        self.remoteHost = remoteHost
        self.scheme = scheme
    
    def run(self, requestLine, headers, rfile):
        """Process the Request.
        
        requestLine should be of the form "GET /path HTTP/1.0".
        headers should be a list of (name, value) tuples.
        rfile should be a file-like object containing the HTTP request
            entity.
        
        When run() is done, the returned object should have 3 attributes:
          status, e.g. "200 OK"
          headers, a list of (name, value) tuples
          body, an iterable yielding strings
        
        Consumer code (HTTP servers) should then access these response
        attributes to build the outbound stream.
        
        """
        if cherrypy.profiler:
            cherrypy.profiler.run(self._run, requestLine, headers, rfile)
        else:
            self._run(requestLine, headers, rfile)
        return cherrypy.response
    
    def _run(self, requestLine, headers, rfile):
        
        try:
            self.headers = headers
            self.headerMap = httptools.HeaderMap()
            self.simpleCookie = Cookie.SimpleCookie()
            self.rfile = rfile
            
            # This has to be done very early in the request process,
            # because request.objectPath is used for config lookups
            # right away.
            self.processRequestLine(requestLine)

            # if we receive OPTIONS * HTTP/1.1
            # then we should simply answer right away
            if self.method == 'OPTIONS':
                # this normally should be * but processRequestLine
                # switched it to 'global' for the configuration handling
                if self.path == 'global':
                    # OPTIONS is defined in HTTP 1.1
                    if self.protocol == 'HTTP/1.1':
                        cherrypy.response.body = []
                        cherrypy.response.status = '200 OK'
                        cherrypy.response.headerMap['Allow'] = 'HEAD, GET, POST, PUT, OPTIONS'
                        cherrypy.response.headerMap['Content-Length'] = 0
                        cherrypy.response.headerMap['Content-Type'] = 'text/plain'
                        cherrypy.response.finalize()
                        _cputil.getSpecialAttribute("_cpLogAccess")()
                        return
                    
{'fraction_non_alphanumeric': 0.07132188200149366, 'fraction_numerical': 0.004107542942494399, 'mean_word_length': 1.8878706199460917, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4976788', 'n_tokens_mistral': 1384, 'n_tokens_neox': 1333, 'n_words': 482}