Request URL
In normal HTTP requests, the URL scheme and host have already been handled by the time the request is sent (and the URL fragment does not exist at the HTTP protocol level at all), meaning the Request-URI is a path-absolute-URL string, possibly followed by ? and a URL-query string.
Request URL
The optional cafile and capath parameters specify a set of trustedCA certificates for HTTPS requests. cafile should point to a singlefile containing a bundle of CA certificates, whereas capath shouldpoint to a directory of hashed certificate files. More information canbe found in ssl.SSLContext.load_verify_locations().
In addition, if proxy settings are detected (for example, when a *_proxyenvironment variable like http_proxy is set),ProxyHandler is default installed and makes sure the requests arehandled through the proxy.
The legacy urllib.urlopen function from Python 2.6 and earlier has beendiscontinued; urllib.request.urlopen() corresponds to the oldurllib2.urlopen. Proxy handling, which was done by passing a dictionaryparameter to urllib.urlopen, can be obtained by usingProxyHandler objects.
data must be an object specifying additional data to send to theserver, or None if no such data is needed. Currently HTTPrequests are the only ones that use data. The supported objecttypes include bytes, file-like objects, and iterables of bytes-like objects.If no Content-Length nor Transfer-Encoding header fieldhas been provided, HTTPHandler will set these headers accordingto the type of data. Content-Length will be used to sendbytes objects, while Transfer-Encoding: chunked as specified inRFC 7230, Section 3.3.1 will be used to send files and other iterables.
For an HTTP POST request method, data should be a buffer in thestandard application/x-www-form-urlencoded format. Theurllib.parse.urlencode() function takes a mapping or sequenceof 2-tuples and returns an ASCII string in this format. It shouldbe encoded to bytes before being used as the data parameter.
origin_req_host should be the request-host of the origintransaction, as defined by RFC 2965. It defaults tohttp.cookiejar.request_host(self). This is the host name or IPaddress of the original request that was initiated by the user.For example, if the request is for an image in an HTML document,this should be the request-host of the request for the pagecontaining the image.
unverifiable should indicate whether the request is unverifiable,as defined by RFC 2965. It defaults to False. An unverifiablerequest is one whose URL the user did not have the option toapprove. For example, if the request is for an image in an HTMLdocument, and the user had no option to approve the automaticfetching of the image, this should be true.
method should be a string that indicates the HTTP request method thatwill be used (e.g. 'HEAD'). If provided, its value is stored in themethod attribute and is used by get_method().The default is 'GET' if data is None or 'POST' otherwise.Subclasses may indicate a different default method by setting themethod attribute in the class itself.
The request will not work as expected if the data object is unableto deliver its content more than once (e.g. a file or an iterablethat can produce the content only once) and the request is retriedfor HTTP redirects or authentication. The data is sent to theHTTP server right away after the headers. There is no support fora 100-continue expectation in the library.
This is a mixin class that helps with HTTP authentication, both to the remotehost and to a proxy. password_mgr, if given, should be something that iscompatible with HTTPPasswordMgr; refer to sectionHTTPPasswordMgr Objects for information on the interface that must besupported. If passwd_mgr also provides is_authenticated andupdate_authenticated methods (seeHTTPPasswordMgrWithPriorAuth Objects), then the handler will use theis_authenticated result for a given URI to determine whether or not tosend authentication credentials with the request. If is_authenticatedreturns True for the URI, credentials are sent. If is_authenticatedis False, credentials are not sent, and then if a 401 response isreceived the request is re-sent with the authentication credentials. Ifauthentication succeeds, update_authenticated is called to setis_authenticated True for the URI, so that subsequent requests tothe URI or any of its super-URIs will automatically include theauthentication credentials.
The HTTP request method to use. By default its value is None,which means that get_method() will do its normal computationof the method to be used. Its value can be set (thus overriding the defaultcomputation in get_method()) either by providing a defaultvalue by setting it at the class level in a Request subclass, or bypassing a value in to the Request constructor via the methodargument.
Add another header to the request. Headers are currently ignored by allhandlers except HTTP handlers, where they are added to the list of headers sentto the server. Note that there cannot be more than one header with the samename, and later calls will overwrite previous calls in case the key collides.Currently, this is no loss of HTTP functionality, since all headers which havemeaning when used more than once have a (header-specific) way of gaining thesame functionality using only one header. Note that headers added usingthis method are also added to redirected requests.
Open the given url (which can be a request object or a string), optionallypassing the given data. Arguments, return values and exceptions raised arethe same as those of urlopen() (which simply calls the open()method on the currently installed global OpenerDirector). Theoptional timeout parameter specifies a timeout in seconds for blockingoperations like the connection attempt (if not specified, the global defaulttimeout setting will be used). The timeout feature actually works only forHTTP, HTTPS and FTP connections.
Handlers with a method named like _open() are called to handlethe request. This stage ends when a handler either returns a non-Nonevalue (ie. a response), or raises an exception (usuallyURLError). Exceptions are allowed to propagate.
The default implementation of this method does not strictly follow RFC 2616,which says that 301 and 302 responses to POST requests must not beautomatically redirected without confirmation by the user. In reality, browsersdo allow automatic redirection of these responses, changing the POST to aGET, and the default implementation reproduces this behavior.
The ProxyHandler will have a method _open() for everyprotocol which has a proxy in the proxies dictionary given in theconstructor. The method will modify requests to go through the proxy, bycalling request.set_proxy(), and call the next handler in the chain toactually execute the protocol.
Handle an authentication request by getting a user/password pair, and re-tryingthe request. authreq should be the name of the header where the informationabout the realm is included in the request, host specifies the URL and path toauthenticate for, req should be the (failed) Request object, andheaders should be the error headers.
authreq should be the name of the header where the information about the realmis included in the request, host should be the host to authenticate to, reqshould be the (failed) Request object, and headers should be theerror headers.
The second argument, if present, specifies the file location to copy to (ifabsent, the location will be a tempfile with a generated name). The thirdargument, if present, is a callable that will be called once onestablishment of the network connection and once after each block readthereafter. The callable will be passed three arguments; a count of blockstransferred so far, a block size in bytes, and the total size of the file. Thethird argument may be -1 on older FTP servers which do not return a filesize in response to a retrieval request.
If the url uses the http: scheme identifier, the optional dataargument may be given to specify a POST request (normally the requesttype is GET). The data argument must be a bytes object in standardapplication/x-www-form-urlencoded format; see theurllib.parse.urlencode() function.
If the url uses the http: scheme identifier, the optional dataargument may be given to specify a POST request (normally the request typeis GET). The data argument must in standardapplication/x-www-form-urlencoded format; see theurllib.parse.urlencode() function.
According to the letter of RFC 2616, 301 and 302 responses to POST requestsmust not be automatically redirected without confirmation by the user. Inreality, browsers do allow automatic redirection of these responses, changingthe POST to a GET, and urllib reproduces this behaviour.
The urllib.response module defines functions and classes which define aminimal file-like interface, including read() and readline().Functions defined by this module are used internally by the urllib.request module.The typical response object is a urllib.response.addinfourl instance:
The HTTP interfaces in Node.js are designed to support many featuresof the protocol which have been traditionally difficult to use.In particular, large, possibly chunk-encoded, messages. The interface iscareful to never buffer entire requests or responses, so theuser is able to stream data.
An Agent is responsible for managing connection persistenceand reuse for HTTP clients. It maintains a queue of pending requestsfor a given host and port, reusing a single socket connection for eachuntil the queue is empty, at which time the socket is either destroyedor put into a pool where it is kept to be used again for requests to thesame host and port. Whether it is destroyed or pooled depends on thekeepAlive option.
Pooled connections have TCP Keep-Alive enabled for them, but servers maystill close idle connections, in which case they will be removed from thepool and a new connection will be made when a new HTTP request is made forthat host and port. Servers may also refuse to allow multiple requestsover the same connection, in which case the connection will have to beremade for every request and cannot be pooled. The Agent will still makethe requests to that server, but each one will occur over a new connection. 041b061a72