Lines Matching +full:decode +full:- +full:uri +full:- +full:component
11 ------------------------------
13 This class implements GET and POST requests to cgi-bin scripts.
18 In all cases, the implementation is intentionally naive -- all
22 -- it may execute arbitrary Python code or external programs.
29 - log requests even later (to capture byte count)
30 - log user-agent header and other interesting goodies
31 - send error log to separate file
37 # HTTP Working Group T. Berners-Lee
38 # INTERNET-DRAFT R. T. Fielding
39 # <draft-ietf-http-v10-spec-00.txt> H. Frystyk Nielsen
42 # URL: http://www.ics.uci.edu/pub/ietf/http/draft-ietf-http-v10-spec-00.txt
54 # ---------
64 # | - otherwise.
66 # | - otherwise.
70 # | hh: hour (24-hour format, the machine's timezone)
74 # | ddd: the status code returned by the server, - if not available.
76 # | *not including the HTTP/1.0 header*, - if not available
116 <meta charset="utf-8">
123 <p>Error code explanation: %(code)s - %(explain)s.</p>
128 DEFAULT_ERROR_CONTENT_TYPE = "text/html;charset=utf-8"
153 :-).
160 2. An optional set of RFC-822-style headers
169 where <command> is a (case-sensitive) keyword such as GET or POST,
195 2. An optional set of RFC-822-style headers
205 <responsecode> is a 3-digit response code indicating success or
207 human-readable string explaining what the response code means.
222 - client_address is the client IP address in the form (host,
225 - command, path and version are the broken-down request line;
227 - headers is an instance of email.message.Message (or a derived
230 - rfile is a file object open for reading positioned at the
233 - wfile is a file object open for writing.
243 Content-type: <type>/<subtype>
250 # The Python system version, truncated to its first component.
254 # The format is multiple whitespace-separated strings,
281 requestline = str(self.raw_requestline, 'iso-8859-1')
289 version = words[-1]
296 # - major and minor numbers MUST be treated as
298 # - HTTP/2.4 is a lower version than HTTP/2.13, which in
300 # - Leading zeros MUST be ignored by recipients.
303 if any(not component.isdigit() for component in version_number):
305 if any(len(component) > 10 for component in version_number):
337 # gh-87389: The purpose of replacing '//' with '/' is to protect
339 # with '//' because http clients treat //path as an absolute URI
365 elif (conntype.lower() == 'keep-alive' and
370 if (expect.lower() == "100-continue" and
378 """Decide what to do with an "Expect: 100-continue" header.
447 *( HTAB / SP / VCHAR / %x80-FF )
471 # - RFC7230: 3.3. 1xx, 204(No Content), 304(Not Modified)
472 # - RFC7231: 6.3.6. 205(Reset Content)
485 body = content.encode('UTF-8', 'replace')
486 self.send_header("Content-Type", self.error_content_type)
487 self.send_header('Content-Length', str(len(body)))
518 'latin-1', 'strict'))
526 ("%s: %s\r\n" % (keyword, value)).encode('latin-1', 'strict'))
531 elif value.lower() == 'keep-alive':
545 def log_request(self, code='-', size='-'):
596 sys.stderr.write("%s - - [%s] %s\n" %
662 '.Z': 'application/octet-stream',
663 '.bz2': 'application/x-bzip2',
664 '.xz': 'application/x-xz',
704 # redirect browser - doing basically what apache does
710 self.send_header("Content-Length", "0")
724 # See discussion on python-dev and Issue34711 regarding
738 if ("If-Modified-Since" in self.headers
739 and "If-None-Match" not in self.headers):
740 # compare If-Modified-Since and time of last file modification
743 self.headers["If-Modified-Since"])
745 # ignore ill-formed values
750 # https://tools.ietf.org/html/rfc7231#section-7.1.1.1
756 # remove microseconds, like in If-Modified-Since
766 self.send_header("Content-type", ctype)
767 self.send_header("Content-Length", str(fs[6]))
768 self.send_header("Last-Modified",
828 self.send_header("Content-type", "text/html; charset=%s" % enc)
829 self.send_header("Content-Length", str(len(encoded)))
834 """Translate a /-separated PATH to the local filename syntax.
873 -- note however that this the default server uses this
885 usable for a MIME Content-type header.
888 up in the table self.extensions_map, using application/octet-stream
902 return 'application/octet-stream'
912 Implements something akin to RFC-2396 5.2 step 6 to parse relative paths.
921 # Query component should not be involved.
929 for part in path_parts[:-1]:
965 return -1
991 # Make rfile unbuffered -- we need to read one line and then pass
1042 cgi_directories = ['/cgi-bin', '/htbin']
1125 decode('ascii')
1133 if self.headers.get('content-type') is None:
1136 env['CONTENT_TYPE'] = self.headers['content-type']
1137 length = self.headers.get('content-length')
1145 ua = self.headers.get('user-agent')
1165 # Unix -- fork as we should
1197 # Non-Unix -- use subprocess
1204 interp = interp[:-5] + interp[-4:]
1205 cmdline = [interp, '-u'] + cmdline
1278 parser.add_argument('--cgi', action='store_true',
1280 parser.add_argument('-b', '--bind', metavar='ADDRESS',
1283 parser.add_argument('-d', '--directory', default=os.getcwd(),
1286 parser.add_argument('-p', '--protocol', metavar='VERSION',
1299 # ensure dual-stack is not disabled; ref #38907