Fastcgi协议定义解释与说明
发布日期:2021-05-15 03:00:58 浏览次数:19 分类:博客文章

本文共 7078 字,大约阅读时间需要 23 分钟。

���������������������������������������������������������������������������������������������

������������
���������������������������������

������ 0  1  2  3  4  5  6  7 ...
������ 01 06 00 01 01 1D 03 00...

������0������01������version������������1������
������1������06������type���������FCGI_STDOUT������������������������
������2 3���00 01���������2���������������id������������1������������������������������������������������������id���������������������������������������id������1���
������4 5���01 1D���������2���������������������������������65535������������������������������(0x01 << 8) + 0x1D = 285
������6���03���������������padding������������������������8������������������������������������������������0������������������8 - 285 % 8 = 3���������������������������285������������������������������������������������������8������������������
������7���00������������������
8���������������7���������������������������contentData���������������������paddingData���
���������������web���������������������������������������������������

������ 0  1  2  3  4  5  6  7 ...
������ 01 03 00 01 00 08 00 00...

������������1���03���type������FCGI_END_REQUEST���������������������8���������������contentData���EndRequestBody������paddingData
EndRequestBody���������������������������������������������

typedef struct {
     unsigned char appStatusB3;
     unsigned char appStatusB2;
     unsigned char appStatusB1;
     unsigned char appStatusB0;
     unsigned char protocolStatus;
     unsigned char reserved[3];
} FCGI_EndRequestBody;

appStatus������������������������������cgi���������������������������������������������The application sets the protocolStatus component to FCGI_REQUEST_COMPLETE and the appStatus component to the status code that the CGI program would have returned via the exit system call.���Linux������������������������������������0���������������������������������������
protocolStatus���������������

#define FCGI_REQUEST_COMPLETE 0
#define FCGI_CANT_MPX_CONN 1
#define FCGI_OVERLOADED 2
#define FCGI_UNKNOWN_ROLE 3

������������FCGI_END_REQUEST���contentData���

������ 0  1  2  3  4  5  6  7
������ 00 00 00 00 00 00 00 00

0-3���������appStatus
4������protocolStatus���0���FCGI_REQUEST_COMPLETE���
5-7������������������3������reserved[3]
������������

������ 0  1  2  3  4  5  6  7 ...
������ 01 01 00 01 00 08 00 00...

������0������01������version
������1������01������type���������FCGI_BEGIN_REQUES��������������������������� 
������2 3���00 01���������2���������������id������������1������
������������������������������������������������������contentData���������������

typedef struct {
     unsigned char roleB1;
     unsigned char roleB0;
     unsigned char flags;
     unsigned char reserved[5];
} FCGI_BeginRequestBody;

 

#role���������������������������
#define FCGI_RESPONDER 1
#define FCGI_AUTHORIZER 2
#define FCGI_FILTER 3

���������1���FCGI_RESPONDER������������������������������CGI/1.1���������������http���������������
flags���0���������������������������������������������

������ 0  1  2  3  4  5  6  7
������ 00 01 00 00 00 00 00 00

0���1������������role���1���FCGI_RESPONDER���
2���������flags 0
3-7���������reserved[5]
������������������FCGI_PARAMS������Name-Value Pairs���������������������������������������������������������http������header���headerName-headerValue���������������������������������������������
���������������������������������

typedef struct {
     unsigned char nameLengthB0; /* nameLengthB0 >> 7 == 0 */
     unsigned char valueLengthB3; /* valueLengthB3 >> 7 == 1 */
     unsigned char valueLengthB2;
     unsigned char valueLengthB1;
     unsigned char valueLengthB0;
     unsigned char nameData[nameLength];
     unsigned char valueData[valueLength
     ((B3 & 0x7f) << 24) + (B2 << 16) + (B1 << 8) + B0];
} FCGI_NameValuePair14;

���������������������

������ 0  1  2  3  4  5  6  7 ...
������ 00 04 00 01 04 EB 05 00...

������1���04���������FCGI_PARAMS
������7������������������������������Name������������nameLength������������Value������������valueLength���������������nameData������������valueData���
������������������������������������������������127������������������4���������������������

������ 0  1  2  3  4  5  6  7 ............
������ 0F 80 00 00 91 S  C  R IPT_FILENAME/data/www/......

������0���0F���������������15���SCRIPT_FILENAME������������������������127���������������������
������1���80���������������128���������127������������������4���������80 00 00 91���������������

((B3 & 0x7f) << 24) + (B2 << 16) + (B1 << 8) + B0

���������������������������������������������������������������������������������������������������

������������
������������������������������
���������������������������
���������Records���������������������������������������������������������������������������

typedef struct {
     unsigned char version;
     unsigned char type;
     unsigned char requestIdB1;
     unsigned char requestIdB0;
     unsigned char contentLengthB1;
     unsigned char contentLengthB0;
     unsigned char paddingLength;
     unsigned char reserved;
     unsigned char contentData[contentLength];
     unsigned char paddingData[paddingLength];
} FCGI_Record;

#���������������������Header���������������������������������+���������������������htpp������������header+body���������������
#������������������������������������FCGI_Header���������������������������������������

typedef struct {
     unsigned char version;
     unsigned char type;
     unsigned char requestIdB1;
     unsigned char requestIdB0;
     unsigned char contentLengthB1;
     unsigned char contentLengthB0;
     unsigned char paddingLength;
     unsigned char reserved;
} FCGI_Header;

 

#version���������1
#define FCGI_VERSION_1 1

#type������������������������������FCGI_BEGIN_REQUEST������������������ FCGI_END_REQUEST������������������ FCGI_PARAMS���fastcgi���������������������������������������HTTP_USER_AGENT��� FCGI_STDOUT���fastcgi���������������������������������������������

#define FCGI_BEGIN_REQUEST 1
#define FCGI_ABORT_REQUEST 2
#define FCGI_END_REQUEST 3
#define FCGI_PARAMS 4
#define FCGI_STDIN 5
#define FCGI_STDOUT 6
#define FCGI_STDERR 7
#define FCGI_DATA 8
#define FCGI_GET_VALUES 9
#define FCGI_GET_VALUES_RESULT 10
#define FCGI_UNKNOWN_TYPE 11
#define FCGI_MAXTYPE (FCGI_UNKNOWN_TYPE)

Fastcgi���������������
������������
FAQ���
1 ������������web������������������fastcgi������������������������
������������������python������������������������������nginx������fastcgi������������������������������python������������������������������������������������������������������������nginx���������������
2 ���������������������������������������������������
������������������������������������������������������fastcgi������������php-fpm���������������������������������
3 ������������������������������������������
Linux������������xxd������������������������������������������Windows���������������������������������������������������������21������������$59.95������������������������������������������������������

 

���������http://www.cppblog.com/woaidongmao/archive/2011/06/21/149100.html

上一篇:【InjectFix】00 Unity代码逻辑热修复 Unity下Bug修复神器,腾讯InjectFix开源啦!
下一篇:linux exec函数族

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2025年04月07日 12时13分36秒