Skip to content

Commit 03ff166

Browse files
authored
Merge pull request #73 from tmm1/fix-jruby-support
JRuby: Revert unimplemented "status" support and fix an failed test
2 parents 7eeba55 + 1d76de1 commit 03ff166

3 files changed

Lines changed: 11 additions & 26 deletions

File tree

Rakefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
# load tasks
21
require 'bundler/gem_tasks'
3-
Dir['tasks/*.rake'].sort.each { |f| load f }
42

53
# default task
64
task :compile => :submodules
75
task :default => [:compile, :spec]
6+
7+
# load tasks
8+
Dir['tasks/*.rake'].sort.each { |f| load f }

ext/ruby_http_parser/org/ruby_http_parser/RubyHttpParser.java

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ public class StopException extends RuntimeException {
6767
private IRubyObject on_body;
6868
private IRubyObject on_message_complete;
6969

70-
private IRubyObject status;
7170
private IRubyObject requestUrl;
7271
private IRubyObject requestPath;
7372
private IRubyObject queryString;
@@ -114,18 +113,6 @@ public RubyHttpParser(final Ruby runtime, RubyClass clazz) {
114113
private void initSettings() {
115114
this.settings = new ParserSettings();
116115

117-
this.settings.on_status = new HTTPDataCallback() {
118-
public int cb(http_parser.lolevel.HTTPParser p, ByteBuffer buf, int pos, int len) {
119-
byte[] data = fetchBytes(buf, pos, len);
120-
if (runtime.is1_9() || runtime.is2_0()) {
121-
((RubyString) status).cat(data, 0, data.length, UTF8);
122-
} else {
123-
((RubyString) status).cat(data);
124-
}
125-
return 0;
126-
}
127-
};
128-
129116
this.settings.on_url = new HTTPDataCallback() {
130117
public int cb(http_parser.lolevel.HTTPParser p, ByteBuffer buf, int pos, int len) {
131118
byte[] data = fetchBytes(buf, pos, len);
@@ -222,14 +209,12 @@ public int cb(http_parser.lolevel.HTTPParser p) {
222209
headers = new RubyHash(runtime);
223210

224211
if (runtime.is1_9() || runtime.is2_0()) {
225-
status = RubyString.newEmptyString(runtime, UTF8);
226212
requestUrl = RubyString.newEmptyString(runtime, UTF8);
227213
requestPath = RubyString.newEmptyString(runtime, UTF8);
228214
queryString = RubyString.newEmptyString(runtime, UTF8);
229215
fragment = RubyString.newEmptyString(runtime, UTF8);
230216
upgradeData = RubyString.newEmptyString(runtime, UTF8);
231217
} else {
232-
status = RubyString.newEmptyString(runtime);
233218
requestUrl = RubyString.newEmptyString(runtime);
234219
requestPath = RubyString.newEmptyString(runtime);
235220
queryString = RubyString.newEmptyString(runtime);
@@ -331,8 +316,7 @@ private void init() {
331316
this.parser = new HTTPParser();
332317
this.parser.HTTP_PARSER_STRICT = true;
333318
this.headers = null;
334-
335-
this.status = runtime.getNil();
319+
336320
this.requestUrl = runtime.getNil();
337321
this.requestPath = runtime.getNil();
338322
this.queryString = runtime.getNil();
@@ -469,11 +453,6 @@ public IRubyObject getHeaders() {
469453
return headers == null ? runtime.getNil() : headers;
470454
}
471455

472-
@JRubyMethod(name = "status")
473-
public IRubyObject getStatus() {
474-
return status == null ? runtime.getNil() : status;
475-
}
476-
477456
@JRubyMethod(name = "request_url")
478457
public IRubyObject getRequestUrl() {
479458
return requestUrl == null ? runtime.getNil() : requestUrl;

spec/parser_spec.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,10 +406,15 @@
406406
expect(@parser.send("http_minor")).to eq(test["http_minor"])
407407

408408
if test['type'] == 'HTTP_REQUEST'
409-
expect(@parser.send("request_url")).to eq(test["request_url"].force_encoding(Encoding::BINARY))
409+
if defined?(JRUBY_VERSION)
410+
expect(@parser.send("request_url")).to eq(test["request_url"])
411+
else
412+
# It's created by rb_str_new(), so that encoding is Encoding::ASCII_8BIT a.k.a Encoding::BINARY
413+
expect(@parser.send("request_url")).to eq(test["request_url"].force_encoding(Encoding::ASCII_8BIT))
414+
end
410415
else
411416
expect(@parser.send("status_code")).to eq(test["status_code"])
412-
expect(@parser.send("status")).to eq(test["status"].force_encoding(Encoding::BINARY))
417+
expect(@parser.send("status")).to eq(test["status"].force_encoding(Encoding::ASCII_8BIT)) if !defined?(JRUBY_VERSION)
413418
end
414419

415420
expect(@headers.size).to eq(test['num_headers'])

0 commit comments

Comments
 (0)