Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2014-03

fcl-web deleted headers?

6 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Leonardo M. Ramé

Hi, I'm sending a custom header I called "Filename" to a Brook CGI (which uses TRequest from fcl-web) but I can't access that header.

Here's what I capture on the Network tab on Chrome's developer tools;

POST /cgi-bin/gtir2/test/ HTTP/1.1
Host: 127.0.0.1:8080
Connection: keep-alive
Content-Length: 36409
Origin: http://127.0.0.1:8080
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1897.2 Safari/537.36 Filename: 1234
Content-Type: application/vnd.oasis.opendocument.text Accept: */*
Referer: http://127.0.0.1:8080/gtirii/
Accept-Encoding: gzip,deflate,sdch
Accept-Language: es-419,es;q=0.8,en;q=0.6

And here's what I capture with fcl-web:

Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:es-419,es;q=0.8,en;q=0.6
Connection:keep-alive
Content-Length:36409
Content-Type:application/vnd.oasis.opendocument.text Referer:http://127.0.0.1:8080/gtirii/
Server:127.0.0.1
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1897.2 Safari/537.36 Host:/
Cache-Control:/var/www/index.html
X-Requested-With:127.0.0.1

The code I'm using to print the header's output is this (on a POST handler):

  for I := 0 to TheRequest.FieldCount - 1 do
  begin
    lAccession := lAccession +
      TheRequest.FieldNames[I] + ':' + TheRequest.FieldValues[I] + '<br>';
  end;
  raise Exception.Create(lAccession);

Why the difference?

Btw, I'm using fpc 2.7.1 compiled from trunk just before asking here, on linux x86_64 and Lazarus trunk.

Regards,

Reply by email

Leonardo M. Ramé
to Leonardo M. Ramé
Leonardo M. Ram? wrote 48 lines
Hi, I'm sending a custom header I called "Filename" to a Brook CGI (which uses TRequest from fcl-web) but I can't access that header. Here's what I capture on the Network tab on Chrome's developer tools; POST /cgi-bin/gtir2/test/ HTTP/1.1 Host: 127.0.0.1:8080 Connection: keep-alive Content-Length: 36409 Origin: http://127.0.0.1:8080 User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1897.2 Safari/537.36 Filename: 1234 Content-Type: application/vnd.oasis.opendocument.text Accept: */* Referer: http://127.0.0.1:8080/gtirii/ Accept-Encoding: gzip,deflate,sdch Accept-Language: es-419,es;q=0.8,en;q=0.6 And here's what I capture with fcl-web: Accept:*/* Accept-Encoding:gzip,deflate,sdch Accept-Language:es-419,es;q=0.8,en;q=0.6 Connection:keep-alive Content-Length:36409 Content-Type:application/vnd.oasis.opendocument.text Referer:http://127.0.0.1:8080/gtirii/ Server:127.0.0.1 User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1897.2 Safari/537.36 Host:/ Cache-Control:/var/www/index.html X-Requested-With:127.0.0.1 The code I'm using to print the header's output is this (on a POST handler): for I := 0 to TheRequest.FieldCount - 1 do begin lAccession := lAccession + TheRequest.FieldNames[I] + ':' + TheRequest.FieldValues[I] + '<br>'; end; raise Exception.Create(lAccession); Why the difference? Btw, I'm using fpc 2.7.1 compiled from trunk just before asking here, on linux x86_64 and Lazarus trunk.

Well, I ended up adding the data as a querystring:

/cgi-bin/test?filename=1234

And doing a POST with that.

Reply by email

Ludo Brands
to Michael Van Canneyt
Michael Van Canneyt wrote 10 lines
On Thu, 27 Mar 2014, Leonardo M. Ram? wrote: > Hi, I'm sending a custom header I called "Filename" to a Brook CGI > (which uses TRequest from fcl-web) but I can't access that header. To my knowledge, the CGI protocol doesn't support the use of custom headers.

AFAIK, the CGI protocol doesn't specify anything regarding custom headers. It only specifies mandatory variables but leaves custom headers to the webserver implementation. Apache forwards most headers in environment variables (http://httpd.apache.org/docs/trunk/env.html). But, CustCgi only reads a set of known variables listed in CgiVarNames.

Can you try

HTTPDecode(GetEnvironmentVariable('Filename'));

to get your custom header?

A good practice is to start your custom headers with 'X-YourAPP-'. Headers starting with 'X-' are in a lot of implementations considered as application specific headers and not touched by transport agents.

Ludo

Reply by email

Michael Van Canneyt
to Ludo Brands
Ludo Brands wrote 27 lines
On 03/27/2014 10:57 PM, Michael Van Canneyt wrote: > > > On Thu, 27 Mar 2014, Leonardo M. Ram? wrote: > >> Hi, I'm sending a custom header I called "Filename" to a Brook CGI >> (which uses TRequest from fcl-web) but I can't access that header. > > To my knowledge, the CGI protocol doesn't support the use of custom > headers. > AFAIK, the CGI protocol doesn't specify anything regarding custom headers. It only specifies mandatory variables but leaves custom headers to the webserver implementation. Apache forwards most headers in environment variables (http://httpd.apache.org/docs/trunk/env.html). But, CustCgi only reads a set of known variables listed in CgiVarNames. Can you try HTTPDecode(GetEnvironmentVariable('Filename')); to get your custom header? A good practice is to start your custom headers with 'X-YourAPP-'. Headers starting with 'X-' are in a lot of implementations considered as application specific headers and not touched by transport agents.

If this is indeed the case, then I will add a GetCustomHeader to the TRequest. TResponse has SetCustomHeader() so this is nicely symmetric.

Michael.

Reply by email