Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8070071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:16:36+00:00 2026-06-05T13:16:36+00:00

I’m trying to use HTTP::Proxy to server 403 error for some specific domain. I

  • 0

I’m trying to use HTTP::Proxy to server 403 error for some specific domain. I already managed to modify headers, but the proxy continue to serve the original page.

Here is the code I’m using:

package Filters::Filter403;

use strict;
use warnings;
use HTTP::Proxy::HeaderFilter::simple;
use HTTP::Proxy::BodyFilter::simple;

our $header = HTTP::Proxy::HeaderFilter::simple->new (
    sub {
        $_[2]->code( 403 );
        $_[2]->message ( 'Forbidden' );
    }
);

our $body = HTTP::Proxy::BodyFilter::simple->new (
    sub {       
        $_[1] = \<<'HTML';
<!DOCTYPE html>
<html><head><title>403 Forbidden</title><style type="text/css">
body { padding: 40pt; }
body, h1, h2, p { color: #333; font-family: Arial, sans-serif; margin: 0; }
div { width: 200px; background: #eee; padding: 2em; }
</style></head><body><div><h1>403</h1><h2>Forbidden</h2></div></body></html>
HTML
    }
);

1;

Here is the code from the main script where I’m calling this two filters, so you can have a better look:

use HTTP::Proxy qw(:log);
use Getopt::Long;

use FindBin qw($Bin);
use lib $Bin;

use Filters;
use HTTP::Proxy::BodyFilter::complete;

my $port = 3128;
my $fail_at;
my $outputfile = '/var/log/cvmfs-test/webproxy.output';
my $errorfile = '/var/log/cvmfs-test/webproxy.error';

my $ret = GetOptions ( "port=i" => \$port,
                       "fail=s" => \$fail_at );

my @fail_at = split(/,/, $fail_at);

# Opening file for log
open (LOG, '>>', $outputfile);

my $proxy = HTTP::Proxy->new;
$proxy->port( $port );
$proxy->logfh( *LOG );
$proxy->logmask( ALL );

if ($fail_at[0] ne 'all') {
    foreach my $url (@fail_at) {
        $proxy->push_filter(
            host => $url,
            response => HTTP::Proxy::BodyFilter::complete->new,
            response => $Filters::Filter403::header,
            response => $Filters::Filter403::body
        );
    }
}
else {
    $proxy->push_filter (
        response => HTTP::Proxy::BodyFilter::complete->new(),
        response => $Filters::Filter403::header,
        response => $Filters::Filter403::body
    );
}

my $pid = fork();

# Command for the forked process
if ( defined($pid) and $pid == 0 ) {
    open (my $errfh, '>', $errorfile);
    STDOUT->fdopen( \*$errfh, 'w' ) || die "Couldn't set STDERR to $errorfile: $!\n";
    $proxy->start;
}

# Command for the main script
unless ($pid == 0) {
    print "Proxy HTTP started on port $port with PID $pid.\n";
    print "You can read its output in $outputfile.\n";
}

exit 0;

Can you please help me?
I tried Daxim solution and I also tried to use $ { $_[1] } as documentation seems to suggest, but it didn’t works.

Thank you very much.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T13:16:38+00:00Added an answer on June 5, 2026 at 1:16 pm

    I have found a solution.
    The problem is that every filter after HTTP::Proxy::BodyFilter::complete->new is executed with empty data. I found that loading an heavy page, my code were added multiple times.

    Here is the working filter:

    our $body = HTTP::Proxy::BodyFilter::simple->new (
        sub {
            my ( $self, $dataref, $message, $protocol, $buffer ) = @_;
            unless (defined ($buffer)){
                my $html = 
                        '<!DOCTYPE html>'.
                        '<html><head><title>403 Forbidden</title><style type="text/css">'.
                        'body { padding: 40pt; }'.
                        'body, h1, h2, p { color: #333; font-family: Arial, sans-serif; margin: 0; }'.
                        'div { width: 200px; background: #eee; padding: 2em; }'.
                        '</style></head><body><div><h1>403</h1><h2>Forbidden</h2></div></body></html>';
    
                $$dataref = $html;
            }
        }
    );
    

    This way, the filter doesn’t do anything unless $buffer is undef, i.e. when the whole response was received.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.