Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Прочее";
Текущий архив: 2008.09.21;
Скачать: [xml.tar.bz2];

Вниз

переменные окружения и CGI в Delphi   Найти похожие ветки 

 
Ega23 ©   (2008-08-01 12:04) [0]

Столкнулся с интересной проблемой. Есть такой файл $(DELPHI)\Source\Internet\CGIHTTP.pas
Там есть CGIServerVariables: array[0..28] of string = (...)
В частности, один из параметров называется "HTTP_CONTENT_LENGTH", насколько я понял, отвечает за размер буфера, приходящего в STDIN.

Так вот, эта штука не работает. Но как только значение меняю на "CONTENT_LENGTH" - всё сразу становится замечательно.

В связи с этим 2 вопроса:
1. Это баг или фича? И вообще, как это понимать?
2. Где взять полный и корректный список того, что приходит в HTTP-запросе?


 
Anatoly Podgoretsky ©   (2008-08-01 12:40) [1]

> Ega23  (01.08.2008 12:04:00)  [0]

Смотри TWebRequest
Кроме того это обычные системные переменные, так что можно даже просто посмотреть весь список через АПИ GetEnvironmentStrings.


 
Anatoly Podgoretsky ©   (2008-08-01 12:45) [2]

Вот небольшок кусочек по иследованию переменных
Часть первая:

procedure TPersonalModule.EnvPageProducerHTMLTag(Sender: TObject; Tag: TTag; const TagString: string; TagParams: TStrings; var ReplaceText: string);
var
 I: Integer;
begin
 if TagString = "ENV" then begin
   ReplaceText :=
     "SERVER_SOFTWARE: " + Request.GetFieldByName("SERVER_SOFTWARE") + "<BR>" +
     "SERVER_NAME: " + Request.GetFieldByName("SERVER_NAME") + "<BR>" +
     "GATEWAY_INTERFACE: " + Request.GetFieldByName("GATEWAY_INTERFACE") + "<BR>" +
     "SERVER_PROTOCOL: " + Request.GetFieldByName("SERVER_PROTOCOL") + "<BR>" +
     "SERVER_PORT: " + Request.GetFieldByName("SERVER_PORT") + "<BR>" +
     "REQUEST_METHOD: " + Request.GetFieldByName("REQUEST_METHOD") + "<BR>" +
     "PATH_INFO: " + Request.GetFieldByName("PATH_INFO") + "<BR>" +
     "PATH_TRANSLATED: " + Request.GetFieldByName("PATH_TRANSLATED") + "<BR>" +
     "SCRIPT_NAME: " + Request.GetFieldByName("SCRIPT_NAME") + "<BR>" +
     "QUERY_STRING: " + Request.GetFieldByName("QUERY_STRING") + "<BR>" +
     "REMOTE_HOST: " + Request.GetFieldByName("REMOTE_HOST") + "<BR>" +
     "REMOTE_ADDR: " + Request.GetFieldByName("REMOTE_ADDR") + "<BR>" +
     "AUTH_TYPE: " + Request.GetFieldByName("AUTH_TYPE") + "<BR>" +
     "REMOTE_USER: " + Request.GetFieldByName("REMOTE_USER") + "<BR>" +
     "REMOTE_IDENT: " + Request.GetFieldByName("REMOTE_IDENT") + "<BR>" +
     "CONTENT_TYPE: " + Request.GetFieldByName("CONTENT_TYPE") + "<BR>" +
     "CONTENT_LENGTH: " + Request.GetFieldByName("CONTENT_LENGTH") + "<BR>" +
     "HTTP_ACCEPT: " + Request.GetFieldByName("HTTP_ACCEPT") + "<BR>" +
     "HTTP_USER_AGENT: " + Request.GetFieldByName("HTTP_USER_AGENT");

   ReplaceText := ReplaceText + "<H1>Properies</H1>" +
     "<table>"+
       "<TR><TD>Accept:</TD><TD>" + Request.Accept +  "</TD></TR>" + // (public)  Reports the value of the Accept header of the HTTP request message.
       "<TR><TD>Authorization:</TD><TD> " + Request.Authorization + "</TD></TR>" + //  (public)  Reports the value of the Authorization header of the HTTP request message.
       "<TR><TD>CacheControl:</TD><TD> " + Request.CacheControl + "</TD></TR>" + //  (public)  Reports the value of the Cache-Control header of the HTTP request message.
       "<TR><TD>Connection:</TD><TD> " + Request.Connection + "</TD></TR>" + //  (public)  Reports the value of the Connection header of the HTTP request message.
       "<TR><TD>Content:</TD><TD> " + Request.Content + "</TD></TR>" + //  (public)  Represents the unparsed contents of the HTTP request message.
       "<TR><TD>ContentEncoding:</TD><TD> " + Request.ContentEncoding + "</TD></TR>" + //  (public)  Reports the value of the Content-Encoding header of the HTTP request message.
       "<TR><TD>ContentFields:</TD><TD> </TD></TR>"; //  (public)  Reports the value of the Date header of the HTTP request message.
   for I := 0 to Request.ContentFields.Count - 1 do begin
     ReplaceText := ReplaceText + "<TR><TD>   " + Request.ContentFields[I] + "</TD></TR>";
   end;
   ReplaceText := ReplaceText + "<TR><TD>ContentLength:</TD><TD> " + IntToStr(Request.ContentLength) + "</TD></TR>" + //  (public)  Reports the value of the Content-Length header of the HTTP request message.
//      "ContentParser: " + Request.ContentParser + "<BR>" + //  (public)  Refers to the object"s content parser object.
       "<TR><TD>ContentType:</TD><TD> " + Request.ContentType + "</TD></TR>" + //  (public)  Reports the value of the Content-Type header of the HTTP request message.
       "<TR><TD>ContentVersion:</TD><TD> " + Request.ContentVersion + "</TD></TR>" + //  (public)  Reports the value of the Content-Version header of the HTTP request message.
       "<TR><TD>Cookie:</TD><TD> " + Request.Cookie + "</TD></TR>" + //  (public)  Reports the value of the Cookie header of the HTTP request message.
       "<TR><TD>CookieFields:</TD><TD> </TD></TR>"; //  (public)  Reports the value of the Date header of the HTTP request message.
   for I := 0 to Request.CookieFields.Count - 1 do begin
     ReplaceText := ReplaceText + "<TR><TD>   " + Request.CookieFields[I] + "</TD></TR>";
   end;
   ReplaceText := ReplaceText + "<TR><TD>Date:</TD><TD>";


 
Anatoly Podgoretsky ©   (2008-08-01 12:46) [3]

Часть вторая

   if Request.Date > 0 then
     ReplaceText := ReplaceText + DateTimeToStr(Request.Date)
   else begin
     ReplaceText := ReplaceText + "N/A";
   end;
     ReplaceText := ReplaceText + "</TD></TR>" +
       "<TR><TD>DerivedFrom:</TD><TD> " + Request.DerivedFrom + "</TD></TR>"; //  (public)  Reports the value of the Derived-From header of the HTTP request message.
   ReplaceText := ReplaceText + "<TR><TD>Expires:</TD><TD>";
   if Request.Expires > 0 then
     ReplaceText := ReplaceText + DateTimeToStr(Request.Expires)
   else begin
     ReplaceText := ReplaceText + "N/A";
   end;
     ReplaceText := ReplaceText + "</TD></TR>" +
//      "Files: " + Request.Files + "<BR>" + //  (public)  Provides access to the files uploaded in the HTTP request.
       "<TR><TD>From:</TD><TD> " + Request.From + "</TD></TR>" + //  (public)  Reports the value of the From header of the HTTP request message.
       "<TR><TD>Host:</TD><TD> " + Request.Host + "</TD></TR>"; //  (public)  Reports the value of the Host header of the HTTP request message.
   ReplaceText := ReplaceText + "<TR><TD>IfModifiedSince:</TD><TD>";
   if Request.IfModifiedSince > 0 then
     ReplaceText := ReplaceText + DateTimeToStr(Request.IfModifiedSince)
   else begin
     ReplaceText := ReplaceText + "N/A";
   end;
     ReplaceText := ReplaceText + "</TD></TR>" +
       "<TR><TD>InternalPathInfo:</TD><TD> " + Request.InternalPathInfo + "</TD></TR>" + //  (public)  Returns the path info portion of the URL.
       "<TR><TD>InternalScriptName:</TD><TD> " + Request.InternalScriptName + "</TD></TR>" + //  (public)  Returns the ScriptName part of the URL.
       "<TR><TD>PathInfo:</TD><TD> " + Request.PathInfo + "</TD></TR>" + //  (public)  Reports the value of the path information (if any) of the URL specified in the HTTP request message.
       "<TR><TD>PathTranslated:</TD><TD> " + Request.PathTranslated + "</TD></TR>" + //  (public)  Represents a translation of the PathInfo property to a fully qualified path on the Web server.
       "<TR><TD>ProtocolVersion:</TD><TD> " + Request.ProtocolVersion + "</TD></TR>" + //  (public)  Reports the version number of the HTTP protocol specified in the initial header of the HTTP request message.
       "<TR><TD>Query:</TD><TD> " + Request.Query + "</TD></TR>" + //  (public)  Indicates the value of the query information (if any) of the URL specified in the HTTP request message.
       "<TR><TD>QueryFields:</TD><TD> </TD></TR>"; //  (public)  Reports the value of the Date header of the HTTP request message.
   for I := 0 to Request.QueryFields.Count - 1 do begin
     ReplaceText := ReplaceText + "<TR><TD>   " + Request.QueryFields[I] + "</TD></TR>";
   end;
   ReplaceText := ReplaceText + "<TR><TD>Referer:</TD><TD> " + Request.Referer + "</TD></TR>" + //  (public)  Reports the value of the Referer header of the HTTP request message.
       "<TR><TD>RemoteAddr:</TD><TD> " + Request.RemoteAddr + "</TD></TR>" + //  (public)  Indicates the remote IP address of the client associated with the HTTP request message.
       "<TR><TD>RemoteHost:</TD><TD> " + Request.RemoteHost + "</TD></TR>" + //  (public)  Reports the fully qualified reverse domain lookup of the client associated with the HTTP request message.
       "<TR><TD>ScriptName:</TD><TD> " + Request.ScriptName + "</TD></TR>" + //  (public)  Indicates the value of the script information (if any) of the URL specified in the HTTP request message.
       "<TR><TD>ServerPort:</TD><TD> " + IntToStr(Request.ServerPort) + "</TD></TR>" + //  (public)  Indicates the port number of the port on the Web server that receives the HTTP request message.
       "<TR><TD>Title:</TD><TD> " + Request.Title + "</TD></TR>" + //  (public)  Reports the value of the Title header of the HTTP request message.
       "<TR><TD>URL:</TD><TD> " + Request.URL + "</TD></TR>" + //  (public)  Reports the Uniform Resource Identifier (URI) specified by the HTTP request message to identify the target of the request.
       "<TR><TD>UserAgent:</TD><TD> " + Request.UserAgent + "</TD></TR>" + //  (public)  Reports the value of the User-Agent header of the HTTP request message.
   "</Table>"
 end;
end;


 
Ega23 ©   (2008-08-01 12:56) [4]


> Смотри TWebRequest


Проблема. Нет у меня никакого TWebRequest. Это вообще FastCGI, как консольное приложение.


> Кроме того это обычные системные переменные, так что можно
> даже просто посмотреть весь список через АПИ GetEnvironmentStrings.


Да я вот тоже уже об этом подумал. Вопрос такой: а там все переменные окружения будут "значимые"? Или мусор тоже какой-то будет?


 
Anatoly Podgoretsky ©   (2008-08-01 13:10) [5]

> Ega23  (01.08.2008 12:56:04)  [4]

Я не в курсе насчет, что такое FastCGI - я знаю CGI и WinCGI (это вроде уже погибло, так и не родившись).
Касательно GetEnvironmentStrings - то CGI использует системные переменные для своих целей, как я понимаю это - то при поступление запроса создаются переменные и они добавляются к системным переменным. Единственно НО - я не проверял, это из теории. И второе FastCGI работает ли оно в соотвествии со спецификацией CGI

Но попробовать то не составит труда. Надеюсь ты умеешь работать с WinAPI   :-)


 
Anatoly Podgoretsky ©   (2008-08-01 13:11) [6]

> Ega23  (01.08.2008 12:56:04)  [4]

Любое консольное приложение CGI Ready - поскольку общение идет с помощью StdIn/StrOut + системные переменные, которые готовит ВЕБ сервер.


 
Ega23 ©   (2008-08-01 13:24) [7]


> Я не в курсе насчет, что такое FastCGI


Отличие в том, что FCGI не умирает после ответа серверу. Т.е. При первом запуске инициализировали всё что надо, установили коннекты, выполнили запрос, отправили в StdOut информацию и ушли на ожидание нового запроса.


> Но попробовать то не составит труда. Надеюсь ты умеешь работать
> с WinAPI


Да умею. Вопрос не стоит в том "Как получить переменные окружения для моего процесса". Вопрос в том, какие из этих переменных реально нужны и для чего (ну, для чего это разобраться-то можно, гугл никто не отменял...). И какова вероятность того, что разные веб-сервера не будут создавать одинаковый набор переменных окружения?


 
Anatoly Podgoretsky ©   (2008-08-01 13:41) [8]

> Ega23  (01.08.2008 13:24:07)  [7]

Ну описание переменных надо искать в документации, наверно в первую очередь в RFC
Ты обратил внимание, что я не вывожу HTTP_C... это потому что не несет информации.
Насчет вероятности, она конечно стремится к единице, но не равна ей, кроме того отдельные сервера могут включать и не документированые, собственные переменные.



Страницы: 1 вся ветка

Форум: "Прочее";
Текущий архив: 2008.09.21;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.5 MB
Время: 0.008 c
4-1196879655
EgorovAlex
2007-12-05 21:34
2008.09.21
Динамическое подключение dll


2-1218546159
darova
2008-08-12 17:02
2008.09.21
Восстановить подключение к сетевому диску


15-1217229349
Пробежал...
2008-07-28 11:15
2008.09.21
Хранилище данных


3-1206130189
Леонид
2008-03-21 23:09
2008.09.21
база данных Delphi 7 в формате MS Access


4-1197096509
happy
2007-12-08 09:48
2008.09.21
Пост запрос





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский