Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
378 views
in Technique[技术] by (71.8m points)

bash - 如何使用CASH和BASH检索HTTP请求标头(How to retrieve HTTP request header using CGI with BASH)

I use a CGI script that calls a Java program using Apache 2.4.41.

(我使用一个CGI脚本,该脚本使用Apache 2.4.41调用Java程序。)

The script is the following:

(脚本如下:)

#!usr/bin/bash
java 
 -Dcgi.content_type=$CONTENT_TYPE 
 -Dcgi.content_length=$CONTENT_LENGTH 
 -Dcgi.request_method=$REQUEST_METHOD 
 -Dcgi.query_string=$QUERY_STRING 
 -Dcgi.server_name=$SERVER_NAME 
 -Dcgi.server_port=$SERVER_PORT 
 -Dcgi.script_name=$SCRIPT_NAME 
 -Dcgi.path_info=$PATH_INFO 
 -Dcgi.http_cookie=$HTTP_COOKIE 
 -classpath /home/be 
 cgi.UserEndpointCGI

The client sends to the endpoint a custom header to tell the server which function is request.

(客户端向端点发送一个自定义标头,以告知服务器请求哪个功能。)

The header contains the key-value:

(标头包含键值:)

Y-Request: function_name

The problem is that I don't know how to retrieve Y-Request: function_name header field and i couldn't find an answer on the net.

(问题是我不知道如何检索Y-Request: function_name标头字段,而我在网上找不到答案。)

  ask by Mattia Cabrini translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

From your example , this how you use a arbitrary header

(在您的示例中,这是如何使用任意标头的方法)

 -Dcgi.http_cookie=$HTTP_COOKIE 

The header Y-Request must be available in the variable HTTP_Y_REQUEST .

(标头Y-Request必须在变量HTTP_Y_REQUEST可用。)

You CGI script has a big security, someone can inject arbritrary shell command , you must quote the usage of all variables .

(您的CGI脚本具有很大的安全性,有人可以注入任意shell命令,您必须引用所有变量的用法。)

-Dcgi.http_cookie="$HTTP_COOKIE" 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...