strelka 0.0.1.pre.263 → 0.0.1.pre.265
Sign up to get free protection for your applications and to get access to all the features.
@@ -124,19 +124,14 @@ module Strelka::HTTPResponse::Negotiation
|
|
124
124
|
|
125
125
|
### Stringify the response -- overridden to use the negotiated body.
|
126
126
|
def to_s
|
127
|
-
|
128
|
-
|
129
|
-
self.header_data,
|
130
|
-
self.negotiated_body
|
131
|
-
].join( "\r\n" )
|
127
|
+
self.negotiate
|
128
|
+
super
|
132
129
|
end
|
133
130
|
|
134
131
|
|
135
132
|
### Transform the entity body if it doesn't meet the criteria
|
136
133
|
def negotiated_body
|
137
|
-
|
138
|
-
|
139
|
-
self.negotiate
|
134
|
+
self.negotiate
|
140
135
|
return self.body
|
141
136
|
end
|
142
137
|
|
data/lib/strelka/httpresponse.rb
CHANGED
@@ -111,12 +111,15 @@ class Strelka::HTTPResponse < Mongrel2::HTTPResponse
|
|
111
111
|
|
112
112
|
### Add a charset to the content-type header in +headers+ if possible.
|
113
113
|
def add_content_type_charset( headers )
|
114
|
+
return unless headers.content_type.start_with?( 'text' )
|
115
|
+
|
114
116
|
charset = self.find_header_charset
|
115
117
|
self.log.debug "Setting the charset in the content-type header to: %p" % [ charset.name ]
|
116
118
|
|
117
119
|
headers.content_type.slice!( CONTENT_TYPE_CHARSET_RE ) and
|
118
120
|
self.log.debug " removed old charset parameter."
|
119
|
-
headers.content_type += "; charset=#{charset.name}" unless
|
121
|
+
headers.content_type += "; charset=#{charset.name}" unless
|
122
|
+
charset == Encoding::ASCII_8BIT
|
120
123
|
end
|
121
124
|
|
122
125
|
|
@@ -157,7 +160,7 @@ class Strelka::HTTPResponse < Mongrel2::HTTPResponse
|
|
157
160
|
enc ||= @body.internal_encoding if @body.respond_to?( :internal_encoding )
|
158
161
|
enc ||= @body.external_encoding if @body.respond_to?( :external_encoding )
|
159
162
|
|
160
|
-
self.log.debug "
|
163
|
+
self.log.debug " encoding of the entity body is: %p" % [ enc ]
|
161
164
|
return enc
|
162
165
|
end
|
163
166
|
|
@@ -44,6 +44,20 @@ describe Strelka::HTTPResponse::Negotiation do
|
|
44
44
|
end
|
45
45
|
|
46
46
|
|
47
|
+
it "still stringifies as a valid HTTP response" do
|
48
|
+
@res.puts( "FOOM!" )
|
49
|
+
@res.content_type = 'text/plain'
|
50
|
+
@res.charset = Encoding::UTF_8
|
51
|
+
@res.to_s.should include(
|
52
|
+
'HTTP/1.1 200 OK',
|
53
|
+
'Content-Length: 6',
|
54
|
+
'Content-Type: text/plain; charset=UTF-8',
|
55
|
+
"\r\n\r\nFOOM!"
|
56
|
+
)
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
|
47
61
|
describe "content-alternative callback methods" do
|
48
62
|
|
49
63
|
it "can provide blocks for bodies of several different mediatypes" do
|
@@ -34,14 +34,14 @@ describe Strelka::HTTPResponse do
|
|
34
34
|
end
|
35
35
|
|
36
36
|
|
37
|
-
it "adds a charset to the response's content-type header if one is explicitly set" do
|
37
|
+
it "adds a charset to the response's content-type header if it's text/* and one is explicitly set" do
|
38
38
|
@res.content_type = 'text/html'
|
39
39
|
@res.charset = Encoding::UTF_8
|
40
40
|
|
41
41
|
@res.header_data.should =~ %r{Content-type: text/html; charset=UTF-8}i
|
42
42
|
end
|
43
43
|
|
44
|
-
it "replaces the existing content-type header charset if one is explicitly set" do
|
44
|
+
it "replaces the existing content-type header charset if it's text/* and one is explicitly set" do
|
45
45
|
@res.content_type = 'text/html; charset=iso-8859-1'
|
46
46
|
@res.charset = Encoding::UTF_8
|
47
47
|
|
@@ -50,7 +50,7 @@ describe Strelka::HTTPResponse do
|
|
50
50
|
end
|
51
51
|
|
52
52
|
it "adds a charset to the response's content-type header based on the entity body's encoding " +
|
53
|
-
"if there isn't already one set on the request or the header" do
|
53
|
+
"if it's text/* and there isn't already one set on the request or the header" do
|
54
54
|
@res.body = "Стрелке".encode( 'koi8-r' )
|
55
55
|
@res.content_type = 'text/plain'
|
56
56
|
|
@@ -58,14 +58,14 @@ describe Strelka::HTTPResponse do
|
|
58
58
|
end
|
59
59
|
|
60
60
|
it "adds a charset to the response's content-type header based on the entity body's " +
|
61
|
-
"external encoding if there isn't already one set on the request or the header" do
|
61
|
+
"external encoding if it's text/* and there isn't already one set on the request or the header" do
|
62
62
|
@res.body = File.open( __FILE__, 'r:iso-8859-5' )
|
63
63
|
@res.content_type = 'text/plain'
|
64
64
|
|
65
65
|
@res.header_data.should =~ /charset=iso-8859-5/i
|
66
66
|
end
|
67
67
|
|
68
|
-
it "doesn't replace a charset in
|
68
|
+
it "doesn't replace a charset in a text/* content-type header with one based on the entity body" do
|
69
69
|
@res.body = "Стрелке".encode( 'iso-8859-5' )
|
70
70
|
@res.content_type = 'text/plain; charset=utf-8'
|
71
71
|
|
@@ -81,6 +81,11 @@ describe Strelka::HTTPResponse do
|
|
81
81
|
@res.header_data.should_not =~ /charset/i
|
82
82
|
end
|
83
83
|
|
84
|
+
it "doesn't add a charset to the response's content-type header if it's not text/*" do
|
85
|
+
@res.content_type = 'application/octet-stream'
|
86
|
+
@res.header_data.should_not =~ /charset/i
|
87
|
+
end
|
88
|
+
|
84
89
|
it "strips an existing charset from the response's content-type header if it's explicitly " +
|
85
90
|
"set to ASCII-8BIT" do
|
86
91
|
@res.content_type = 'text/plain; charset=ISO-8859-15'
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|