You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Lars Bruun-Hansen <lb...@gmail.com> on 2021/03/04 07:20:09 UTC

[users@httpd] Customizing the HTTP Reason Phrase

How do I customize the HTTP Reason Phrase ?

Definition: The Reason Phrase is sent in an HTTP response on the very
first line immediately following the status code, for example such
line may look like this:

   HTTP/1.1 401 Unauthorized

In this case "Unauthorized" is the Reason Phrase.

I've tried the Send-as-is Handler [1] which according to its
documentation should be able to do this. For example, I have an .asis
file which looks like this:

----file content begin
Status: 401 Blablabla
Content-type: text/html

<html>
<head>
<title>Foo Bar Title</title>
</head>
<body>
<h1>You can't do that</h1>
</body>
</html>
----file content end

This .asis file gets picked up and used in the response but it doesn't
really change the status code. I've looked into the source code for
the as-is module and can see no evidence that the documentation is
correct in stating that the header named "Status" will actually be
used for anything. As long as the .asis file can be successfully read
then the status code will be 200. That doesn't match the
documentation.

In any case maybe there's another way to customize Reason Phrase?

Thanks.

/Lars

[1] https://httpd.apache.org/docs/2.4/mod/mod_asis.html

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Re: Customizing the HTTP Reason Phrase

Posted by Lars Bruun-Hansen <lb...@gmail.com>.
Solved it !
The module was not loaded. This fixed it:

<IfModule !mod_asis.c>
LoadModule  asis_module    modules/mod_asis.so
</IfModule>

In my (feeble) defense I think I would have expected some
warnings/errors in the log when referring to an unknown handler. (i.e.
in SetHandler, AddHandler or in RewriteRule with "H" flag).
For example, in the logs it would say as output from rewrite module:
   "force filename /mytest/httpd/send-401.asis to have the
Content-handler 'send-as-is'"
and I must admit I took that line as if it was using that handler. But
I know realize that this log statement only indicates intent.

In any case:  Thank you!!      Excellent community response to my
somewhat border case.

/Lars

On Sat, Mar 6, 2021 at 12:43 AM Tatsuki Makino
<ta...@hotmail.com> wrote:
>
> In most cases, mod_asis in httpd.conf will probably remain commented out.
> Everyone's favorite :), mod_cgi and mod_cgid, will be set to use it.
>
> Both mod_asis and mod_cgi use ap_scan_script_header_*, so the response code will change depending on the Status header.
> The special consideration of the Status header is due to the RFC 3875.
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Re: Customizing the HTTP Reason Phrase

Posted by Tatsuki Makino <ta...@hotmail.com>.
In most cases, mod_asis in httpd.conf will probably remain commented out.
Everyone's favorite :), mod_cgi and mod_cgid, will be set to use it.

Both mod_asis and mod_cgi use ap_scan_script_header_*, so the response code will change depending on the Status header.
The special consideration of the Status header is due to the RFC 3875.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Re: Customizing the HTTP Reason Phrase

Posted by Eric Covener <co...@gmail.com>.
> >
> < HTTP/1.1 200 OK
> < Date: Fri, 05 Mar 2021 17:38:08 GMT
> < Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips
> < Last-Modified: Fri, 05 Mar 2021 17:38:04 GMT
> < ETag: "99-5bccd8bdbc707"
> < Accept-Ranges: bytes
> < Content-Length: 153
> < Content-Type: text/html; charset=UTF-8
> <
> Status: 401 Blablabla
> Content-type: text/plain

Your server is not interpreting the .asis file w/ the asis_module. The
plain text is being served as a static file.
It's an issue with the SetHandler-like config.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


[users@httpd] Re: Customizing the HTTP Reason Phrase

Posted by Lars Bruun-Hansen <lb...@gmail.com>.
Thank you for answering, Christophe. Appreciated.

The ErrorDocument directive changes the *body* of an error message.
This is not what I want. I want to change what is known in the HTTP
protocol as "reason phrase".

I'm not sure your Perl test is testing the right thing, but I have to
admit that my Perl skills are rusty.

Let me show a Curl test:

My .asis file looks like this:

--- file begin
Status: 401 Blablabla<CR><LF>
Content-type: text/plain<CR><LF>
<CR><LF>
How are you doing?<LF>
Okay, I hope.<CR><LF>
--- file end

(I've played around with line endings. I've tried to make the file
fully HTTP compliant, thinking that would help, meaning I only use a
single <LF> within the body, while I use <CR><LF> everywhere else. The
Handler is called 'as-is' so my expectation is that such file will be
sent as-is on the wire. In any case, it doesn't seem ti make a
difference)

And then a curl test:

curl --verbose http://mytest.lbruun.net/

--- curl output begin
* About to connect() to mytest.lbruun.net port 80 (#0)
*   Trying 207.180.233.34...
* Connected to mytest.lbruun.net (207.180.233.34) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: mytest.lbruun.net
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Fri, 05 Mar 2021 17:38:08 GMT
< Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips
< Last-Modified: Fri, 05 Mar 2021 17:38:04 GMT
< ETag: "99-5bccd8bdbc707"
< Accept-Ranges: bytes
< Content-Length: 153
< Content-Type: text/html; charset=UTF-8
<
Status: 401 Blablabla
Content-type: text/plain

How are you doing?
Ok, I hope.
* Connection #0 to host mytest.lbruun.net left intact
--- curl output end


As you can see it clearly picks up my .asis file. So misspelled
handler name is certainly not the problem. However, as you can see the
status code is still 200. In my example I expected it to be 401.
To be more precise I would expect curl output line which currently reads...

< HTTP/1.1 200 OK

instead to be

< HTTP/1.1 401 Blablabla


I hope it is now a bit clearer.

I think perhaps the misunderstanding is that I expect the "Status"
header to override the real HTTP status when the server sends its
output, rather than leaving such override for the HTTP client to
interpret.

Thanks

/Lars

On Thu, Mar 4, 2021 at 9:24 PM Christophe JAILLET
<ch...@wanadoo.fr> wrote:
>
>
>
> Le 04/03/2021 à 21:15, Christophe JAILLET a écrit :
> > Le 04/03/2021 à 08:20, Lars Bruun-Hansen a écrit :
> >> How do I customize the HTTP Reason Phrase ?
> >>
> >> Definition: The Reason Phrase is sent in an HTTP response on the very
> >> first line immediately following the status code, for example such
> >> line may look like this:
> >>
> >>     HTTP/1.1 401 Unauthorized
> >>
> >> In this case "Unauthorized" is the Reason Phrase.
> >>
> >> I've tried the Send-as-is Handler [1] which according to its
> >> documentation should be able to do this. For example, I have an .asis
> >> file which looks like this:
> >>
> >> ----file content begin
> >> Status: 401 Blablabla
> >> Content-type: text/html
> >>
> >> <html>
> >> <head>
> >> <title>Foo Bar Title</title>
> >> </head>
> >> <body>
> >> <h1>You can't do that</h1>
> >> </body>
> >> </html>
> >> ----file content end
> >>
> >> This .asis file gets picked up and used in the response but it doesn't
> >> really change the status code. I've looked into the source code for
> >> the as-is module and can see no evidence that the documentation is
> >> correct in stating that the header named "Status" will actually be
> >> used for anything. As long as the .asis file can be successfully read
> >> then the status code will be 200. That doesn't match the
> >> documentation.
> >>
> >> In any case maybe there's another way to customize Reason Phrase?
> >>
> >> Thanks.
> >>
> >> /Lars
> >>
> >> [1] https://httpd.apache.org/docs/2.4/mod/mod_asis.html
> >>
> >
> > Hi,
> > I've tested it with the test framework and it works as expected.
> > (See [1] for the test written in perl, and [2] for the .asis files where
> > the 403 and 404 response codes come from)
> >
> > I've slightly modified the test code ([1]) and I confirm that the status
> > phrase is also left unmodified, as expected.
> >
> >
> > In fact, the response code comes "as-is" from the file itself. It is
> > included in the processing flow of Apache by the
> > 'apr_brigade_insert_file()' at line 95.
> > So you can't find any kind of special "status" handling in the code, as
> > there is no manipulation done on the file content itself.
> >
> >
> > Just in case, the handler name is "send-as-is" (no uppercase S as the
> > first letter as written is your mail). See line 37 of the module source
> > code.
> >
> > CJ
> >
> >
> >
> > [1]:
> > http://svn.apache.org/viewvc/httpd/test/framework/trunk/t/modules/asis.t?revision=647766&view=markup&pathrev=
> >
> >
> > [2]:
> > http://svn.apache.org/viewvc/httpd/test/framework/trunk/t/htdocs/modules/asis/?pathrev=1885573
> >
>
> Hi,
>
> I forgot to add, that the directive that you seem to be looking for is
> ErrorDocument (see
> https://httpd.apache.org/docs/2.4/mod/core.html#errordocument)
>
> CJ

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


[users@httpd] Re: Customizing the HTTP Reason Phrase

Posted by Christophe JAILLET <ch...@wanadoo.fr>.

Le 04/03/2021 à 21:15, Christophe JAILLET a écrit :
> Le 04/03/2021 à 08:20, Lars Bruun-Hansen a écrit :
>> How do I customize the HTTP Reason Phrase ?
>>
>> Definition: The Reason Phrase is sent in an HTTP response on the very
>> first line immediately following the status code, for example such
>> line may look like this:
>>
>>     HTTP/1.1 401 Unauthorized
>>
>> In this case "Unauthorized" is the Reason Phrase.
>>
>> I've tried the Send-as-is Handler [1] which according to its
>> documentation should be able to do this. For example, I have an .asis
>> file which looks like this:
>>
>> ----file content begin
>> Status: 401 Blablabla
>> Content-type: text/html
>>
>> <html>
>> <head>
>> <title>Foo Bar Title</title>
>> </head>
>> <body>
>> <h1>You can't do that</h1>
>> </body>
>> </html>
>> ----file content end
>>
>> This .asis file gets picked up and used in the response but it doesn't
>> really change the status code. I've looked into the source code for
>> the as-is module and can see no evidence that the documentation is
>> correct in stating that the header named "Status" will actually be
>> used for anything. As long as the .asis file can be successfully read
>> then the status code will be 200. That doesn't match the
>> documentation.
>>
>> In any case maybe there's another way to customize Reason Phrase?
>>
>> Thanks.
>>
>> /Lars
>>
>> [1] https://httpd.apache.org/docs/2.4/mod/mod_asis.html
>>
> 
> Hi,
> I've tested it with the test framework and it works as expected.
> (See [1] for the test written in perl, and [2] for the .asis files where 
> the 403 and 404 response codes come from)
> 
> I've slightly modified the test code ([1]) and I confirm that the status 
> phrase is also left unmodified, as expected.
> 
> 
> In fact, the response code comes "as-is" from the file itself. It is 
> included in the processing flow of Apache by the 
> 'apr_brigade_insert_file()' at line 95.
> So you can't find any kind of special "status" handling in the code, as 
> there is no manipulation done on the file content itself.
> 
> 
> Just in case, the handler name is "send-as-is" (no uppercase S as the 
> first letter as written is your mail). See line 37 of the module source 
> code.
> 
> CJ
> 
> 
> 
> [1]: 
> http://svn.apache.org/viewvc/httpd/test/framework/trunk/t/modules/asis.t?revision=647766&view=markup&pathrev= 
> 
> 
> [2]: 
> http://svn.apache.org/viewvc/httpd/test/framework/trunk/t/htdocs/modules/asis/?pathrev=1885573 
> 

Hi,

I forgot to add, that the directive that you seem to be looking for is 
ErrorDocument (see 
https://httpd.apache.org/docs/2.4/mod/core.html#errordocument)

CJ

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


[users@httpd] Re: Customizing the HTTP Reason Phrase

Posted by Christophe JAILLET <ch...@wanadoo.fr>.
Le 04/03/2021 à 08:20, Lars Bruun-Hansen a écrit :
> How do I customize the HTTP Reason Phrase ?
> 
> Definition: The Reason Phrase is sent in an HTTP response on the very
> first line immediately following the status code, for example such
> line may look like this:
> 
>     HTTP/1.1 401 Unauthorized
> 
> In this case "Unauthorized" is the Reason Phrase.
> 
> I've tried the Send-as-is Handler [1] which according to its
> documentation should be able to do this. For example, I have an .asis
> file which looks like this:
> 
> ----file content begin
> Status: 401 Blablabla
> Content-type: text/html
> 
> <html>
> <head>
> <title>Foo Bar Title</title>
> </head>
> <body>
> <h1>You can't do that</h1>
> </body>
> </html>
> ----file content end
> 
> This .asis file gets picked up and used in the response but it doesn't
> really change the status code. I've looked into the source code for
> the as-is module and can see no evidence that the documentation is
> correct in stating that the header named "Status" will actually be
> used for anything. As long as the .asis file can be successfully read
> then the status code will be 200. That doesn't match the
> documentation.
> 
> In any case maybe there's another way to customize Reason Phrase?
> 
> Thanks.
> 
> /Lars
> 
> [1] https://httpd.apache.org/docs/2.4/mod/mod_asis.html
> 

Hi,
I've tested it with the test framework and it works as expected.
(See [1] for the test written in perl, and [2] for the .asis files where 
the 403 and 404 response codes come from)

I've slightly modified the test code ([1]) and I confirm that the status 
phrase is also left unmodified, as expected.


In fact, the response code comes "as-is" from the file itself. It is 
included in the processing flow of Apache by the 
'apr_brigade_insert_file()' at line 95.
So you can't find any kind of special "status" handling in the code, as 
there is no manipulation done on the file content itself.


Just in case, the handler name is "send-as-is" (no uppercase S as the 
first letter as written is your mail). See line 37 of the module source 
code.

CJ



[1]: 
http://svn.apache.org/viewvc/httpd/test/framework/trunk/t/modules/asis.t?revision=647766&view=markup&pathrev=

[2]: 
http://svn.apache.org/viewvc/httpd/test/framework/trunk/t/htdocs/modules/asis/?pathrev=1885573

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org