`
angeloce
  • 浏览: 71036 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

PEP333 wsgi规范1.0不靠谱翻译稿(3)

阅读更多

environ变量

 

 The environ dictionary is required to contain these CGI environment variables, as defined by the Common Gateway Interface specification [2]. The following variables must be present, unless their value would be an empty string, in which case they may be omitted, except as otherwise noted below.

environ字典需要包含这些CGI环境变量, 作为对通用接口规范的定义.下面这些变量必须存在在字典中, 除非它们的值是空字符串, 它们被忽略掉.

 

REQUEST_METHOD
The HTTP request method, such as "GET" or "POST". This cannot ever be an empty string, and so is always required.

 

HTTP请求方法,诸如 GET 或 POST.不能写成空字符串,当然也是必需的.


SCRIPT_NAME
The initial portion of the request URL's "path" that corresponds to the application object, so that the application knows its virtual "location". This may be an empty string, if the application corresponds to the "root" of the server.

 

相对于应用对象请求的URL地址的初始部分, 以使得应用程序知道请求的虚拟地址.这个可以是空字符串, 如果应用位置在服务端的根目录地址.


PATH_INFO
The remainder of the request URL's "path", designating the virtual "location" of the request's target within the application. This may be an empty string, if the request URL targets the application root and does not have a trailing slash.

 

请求URL地址的剩余部分, 指示请求应用目标的虚拟位置. 这个可以是空字符串, 如果请求目标位应用的根目录并且结尾没有反斜杠.


QUERY_STRING
The portion of the request URL that follows the "?", if any. May be empty or absent.

 

在"?"后面的请求URL部分.可以为空或者省略掉.


CONTENT_TYPE
The contents of any Content-Type fields in the HTTP request. May be empty or absent.

 

HTTP请求中所有Content-Type字段的内容. 可以为空或省略.


CONTENT_LENGTH
The contents of any Content-Length fields in the HTTP request. May be empty or absent.

 

HTTP请求中所有Content-Length 字段的内容. 可以为空或省略.


SERVER_NAME, SERVER_PORT
When combined with SCRIPT_NAME and PATH_INFO, these variables can be used to complete the URL. Note, however, that HTTP_HOST, if present, should be used in preference to SERVER_NAME for reconstructing the request URL. See the URL Reconstruction section below for more detail. SERVER_NAME and SERVER_PORT can never be empty strings, and so are always required.

 

在连接SCRIPT_NAME 和PATH_INFO时,这两个变量可以用来完成整个URL. 请注意, 如果HTTP_HOST存在, 应该优先于使用它而不是SERVER_NAME来重建URL. 更多细节请参见下面的 URL Reconstruction 章节. 这两个变量都不能为空, 当然也是必需的.


SERVER_PROTOCOL
The version of the protocol the client used to send the request. Typically this will be something like "HTTP/1.0" or "HTTP/1.1" and may be used by the application to determine how to treat any HTTP request headers. (This variable should probably be called REQUEST_PROTOCOL, since it denotes the protocol used in the request, and is not necessarily the protocol that will be used in the server's response. However, for compatibility with CGI we have to keep the existing name.)

 

客户端发送请求使用的协议版本. 通常这是些类似 "HTTP/1.0" 或 "HTTP/1.1"的东西, 可能会使应用程序来决定如果处理每个HTTP请求头.(这个变量或许应该叫做REQUEST_PROTOCOL, 因为它指的是请求的协议, 不一定代表服务端响应的协议. 然而为了兼容CGI我们必须保留这个名字.)


HTTP_ Variables
Variables corresponding to the client-supplied HTTP request headers (i.e., variables whose names begin with "HTTP_"). The presence or absence of these variables should correspond with the presence or absence of the appropriate HTTP header in the request.

 

与客户端支持的HTTP请求头一致的变量.(也就是以"HTTP_"开头命名的变量.)这些变量是否出现都要与HTTP请求头中的变量保持一致.

 

A server or gateway should attempt to provide as many other CGI variables as are applicable. In addition, if SSL is in use, the server or gateway should also provide as many of the Apache SSL environment variables [5] as are applicable, such as HTTPS=on and SSL_PROTOCOL. Note, however, that an application that uses any CGI variables other than the ones listed above are necessarily non-portable to web servers that do not support the relevant extensions. (For example, web servers that do not publish files will not be able to provide a meaningful DOCUMENT_ROOT or PATH_TRANSLATED.)

 

A WSGI-compliant server or gateway should document what variables it provides, along with their definitions as appropriate. Applications should check for the presence of any variables they require, and have a fallback plan in the event such a variable is absent.

 

Note: missing variables (such as REMOTE_USER when no authentication has occurred) should be left out of the environ dictionary. Also note that CGI-defined variables must be strings, if they are present at all. It is a violation of this specification for a CGI variable's value to be of any type other than str.

 

服务端应该尝试提供其他合适的CGI变量.如果使用了SSL, 也应该提供合适的Apache SSL环境变量, 例如 HTTPS=on 和 SSL_PROTOCOL. 然而请注意, 使用了除上述之外其他CGI两边的应用程序对于不支持相关扩展的web服务器来说是不可移植过来的.(例如, 一个不能发布文件的web服务器不可能提供有意义的DOCUMENT_ROOT 或 PATH_TRANSLATED 变量.)

 

一个遵守WSGI协议的服务端应该记录它会提供什么变量. 应用程序应该检查它需要的变量是否都存在, 如果缺少了某个变量应该有 后备的 方法.

 

注意: 缺失的变量(例如没有发生认证的REMOTE_USER变量)应该从字典中忽略掉. 而且要注意 CGI定义的变量如果存在就一定是个字符串. 它违反了 CGI变量可以是任何类型(不一定要是字符串)的规定.

 
In addition to the CGI-defined variables, the environ dictionary may also contain arbitrary operating-system "environment variables", and must contain the following WSGI-defined variables:

 

除了CGI定义的变量外, environ字典可以包括操作系统的环境变量, 但必须包括下列WSGI定义的变量:

 

wsgi.version

The tuple (1,0), representing WSGI version 1.0.

 

元祖 (1,0), 表示WSGI的版本是1.0

 

wsgi.url_scheme

A string representing the "scheme" portion of the URL at which the application is being invoked. Normally, this will have the value "http" or "https", as appropriate.

 

表示哪个应用会被调用在URL的 "scheme"部分的字符串.通常,  应该是"http" 或"https".

 

wsgi.input

An input stream (file-like object) from which the HTTP request body can be read. (The server or gateway may perform reads on-demand as requested by the application, or it may pre- read the client's request body and buffer it in-memory or on disk, or use any other technique for providing such an input stream, according to its preference.)

 

一个HTTP请求体能读出的输入流(类文件对象).(服务端可能等待应用程序请求再执行读出, 或者提前读出并缓存在内存或硬盘上, 或使用其它技术来提供类似的输入流.)

 

wsgi.errors

An output stream (file-like object) to which error output can be written, for the purpose of recording program or other errors in a standardized and possibly centralized location. This should be a "text mode" stream; i.e., applications should use "\n" as a line ending, and assume that it will be converted to the correct line ending by the server/gateway.

 

For many servers, wsgi.errors will be the server's main error log. Alternatively, this may be sys.stderr, or a log file of some sort. The server's documentation should include an explanation of how to configure this or where to find the recorded output. A server or gateway may supply different error streams to different applications, if this is desired.

 

一个输出流(类文件对象), 错误输出可以使用写人到 记录程序或者其它标准和可能的中央位置错误.(-_-#).这应该是个文本模式流; 例如, 应用程序应该使用"\n"作为行结尾, 并且可以假设它会被服务端转换为正确的行结尾.

 

对于大多数服务器, wsgi.errors是服务器主要的异常日志. 或者可以是sys.stderr或其他种类的log文件. 服务器文档应该包括如何配置这个或在哪里找到记录输出的说明.如果需要, 服务端应该提供不同的异常流到不同的应用中.

 

wsgi.multithread

This value should evaluate true if the application object may be simultaneously invoked by another thread in the same process, and should evaluate false otherwise.

 

如果应用程序可以同时被相同进程的不同现成调用, 这个值应该写为True, 否则写为False.

 

wsgi.multiprocess

This value should evaluate true if an equivalent application object may be simultaneously invoked by another process, and should evaluate false otherwise.

 

如果同一个应用程序可以同时被不同进程调用, 写为True, 否则写为False.

 

wsgi.run_once

This value should evaluate true if the server or gateway expects (but does not guarantee!) that the application will only be invoked this one time during the life of its containing process. Normally, this will only be true for a gateway based on CGI (or something similar).

 

如果服务端期望(但不保证)应用程序在该进程期内仅被调用一次, 该值写为True.通常,对于建在CGI(或类似)的网关该值总为True.

 

Finally, the environ dictionary may also contain server-defined variables. These variables should be named using only lower-case letters, numbers, dots, and underscores, and should be prefixed with a name that is unique to the defining server or gateway. For example, mod_python might define variables with names like mod_python.some_variable.

 

最后, environ字典可以包含某些服务器自定义的变量. 这些变量应该使用lower-case形式命名,包括字符,数字,小数点和下划线,并且应该使用能唯一定义服务端的名字作为前缀.例如,mod_python可以定义一个像 mod_python.some_variable名字的变量.

 

 

 

 

 

 

 

 

 

 

 

分享到:
评论
1 楼 simomo 2011-02-16  
一直在找wsgi是如何将客户端发来的request传递给django的,看了你的翻译才知道是env参数中的wsgi.input的值

多谢啦

相关推荐

Global site tag (gtag.js) - Google Analytics