1
# See bottom of file for license and copyright information
5
---+ package Foswiki::Net::HTTPResponse
7
Fakeup of HTTP::Response for use when LWP is not available. Only implements
8
a small subset of the HTTP::Response methods:
16
See the documentation of HTTP::Response for information about the methods.
20
package Foswiki::Net::HTTPResponse;
25
my ( $class, $message ) = @_;
28
code => 400, # BAD REQUEST
37
my ( $class, $text ) = @_;
38
my $this = new( $class, 'Incomplete headers' );
40
$text =~ s/\r\n/\n/gs;
42
$text =~ s/^(.*?)\n\n//s;
43
# untaint is OK, checked below
45
$this->{content} = $text;
46
if ( $httpHeader =~ s/^HTTP\/[\d.]+\s(\d+)\s([^\r\n]*)//s ) {
48
$this->{message} = TAINT($2 || '');
50
while ( $httpHeader =~ s/^(\S*):\s*(.*)$//m ) {
52
# implicit untaint is OK for header names,
53
# but values need to be retainted
54
$this->{headers}->{ lc($1) } = TAINT($2);
56
if ( $httpHeader =~ /\S/) {
58
$this->{message} = "Unparseable headers in response: $httpHeader";
68
return shift->{message};
72
my ( $this, $h ) = @_;
73
return $this->{headers}->{$h};
77
return shift->{content};
82
return $this->{code} >= 400;
87
return $this->{code} >= 300 && $this->{code} < 400;
92
# Module of Foswiki - The Free and Open Source Wiki, http://foswiki.org/
94
# Copyright (C) 2008-2009 Foswiki Contributors. All Rights Reserved.
95
# Foswiki Contributors are listed in the AUTHORS file in the root
96
# of this distribution. NOTE: Please extend that file, not this notice.
98
# Additional copyrights apply to some or all of the code in this
101
# Copyright (C) 2007 TWiki Contributors. All Rights Reserved.
102
# TWiki Contributors are listed in the AUTHORS file in the root
103
# of this distribution. NOTE: Please extend that file, not this notice.
105
# This program is free software; you can redistribute it and/or
106
# modify it under the terms of the GNU General Public License
107
# as published by the Free Software Foundation; either version 2
108
# of the License, or (at your option) any later version. For
109
# more details read LICENSE in the root of this distribution.
111
# This program is distributed in the hope that it will be useful,
112
# but WITHOUT ANY WARRANTY; without even the implied warranty of
113
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
115
# As per the GPL, removal of this notice is prohibited.