1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2024-10-27 20:34:16 +00:00

HTTP Server: Ignore nginx http headers [#255]

This commit is contained in:
gnosygnu 2018-11-02 20:58:51 -04:00
parent 9a81e1b593
commit 5137eda4fb
2 changed files with 46 additions and 30 deletions

View File

@ -18,16 +18,23 @@ import gplx.core.primitives.*; import gplx.core.btries.*;
public class Http_request_parser {
private boolean dnt;
private int type, content_length;
private byte[] url, protocol, host, user_agent, accept, accept_language, accept_encoding, x_requested_with, cookie, referer, content_type, content_type_boundary, connection, pragma, cache_control, origin;
private byte[] url, protocol, host, user_agent, accept, accept_language,
accept_encoding, x_requested_with, cookie, referer, content_type,
content_type_boundary, connection, pragma, cache_control, origin,
upgrade_request, x_host, x_real_ip;
private Http_post_data_hash post_data_hash;
private final Bry_bfr tmp_bfr = Bry_bfr_.New_w_size(255); private final Btrie_rv trv = new Btrie_rv();
private final Http_server_wtr server_wtr; private final boolean log;
private final Bry_bfr tmp_bfr = Bry_bfr_.New_w_size(255); private final Btrie_rv trv = new Btrie_rv();
private final Http_server_wtr server_wtr; private final boolean log;
public Http_request_parser(Http_server_wtr server_wtr, boolean log) {this.server_wtr = server_wtr; this.log = log;}
public void Clear() {
this.dnt = false;
this.type = this.content_length = 0;
this.url = this.protocol = this.host = this.user_agent = this.accept = this.accept_language = this.accept_encoding = this.x_requested_with = this.cookie
= this.referer = this.content_type = this.content_type_boundary = this.connection = this.pragma = this.cache_control = this.origin = null;
this.url = this.protocol = this.host = this.user_agent = this.accept
= this.accept_language = this.accept_encoding = this.x_requested_with = this.cookie
= this.referer = this.content_type = this.content_type_boundary
= this.connection = this.pragma = this.cache_control = this.origin
= this.upgrade_request = this.x_host = this.x_real_ip
= null;
this.post_data_hash = null;
}
public Http_request_itm Parse(Http_client_rdr rdr) {
@ -82,6 +89,9 @@ public class Http_request_parser {
case Tid_pragma: this.pragma = Bry_.Mid(line, val_bgn, line_len); break;
case Tid_cache_control: this.cache_control = Bry_.Mid(line, val_bgn, line_len); break;
case Tid_origin: this.origin = Bry_.Mid(line, val_bgn, line_len); break;
case Tid_upgrade_request: this.upgrade_request = Bry_.Mid(line, val_bgn, line_len); break;
case Tid_x_host: this.x_host = Bry_.Mid(line, val_bgn, line_len); break;
case Tid_x_real_ip: this.x_real_ip = Bry_.Mid(line, val_bgn, line_len); break;
case Tid_accept_charset: break;
default: throw Err_.new_unhandled(tid);
}
@ -146,28 +156,31 @@ public class Http_request_parser {
private String To_str() {return Make_request_itm().To_str(tmp_bfr, Bool_.N);}
private static final int Tid_get = 1, Tid_post = 2, Tid_host = 3, Tid_user_agent = 4, Tid_accept = 5, Tid_accept_language = 6, Tid_accept_encoding = 7, Tid_dnt = 8
, Tid_x_requested_with = 9, Tid_cookie = 10, Tid_referer = 11, Tid_content_length = 12, Tid_content_type = 13, Tid_connection = 14, Tid_pragma = 15, Tid_cache_control = 16
, Tid_origin = 17, Tid_accept_charset = 18;
private static final Btrie_slim_mgr trie = Btrie_slim_mgr.ci_a7()
.Add_str_int("GET" , Tid_get)
.Add_str_int("POST" , Tid_post)
.Add_str_int("Host:" , Tid_host)
.Add_str_int("User-Agent:" , Tid_user_agent)
.Add_str_int("Accept:" , Tid_accept)
.Add_str_int("Accept-Language:" , Tid_accept_language)
.Add_str_int("Accept-Encoding:" , Tid_accept_encoding)
.Add_str_int("Accept-Charset:" , Tid_accept_charset)
.Add_str_int("DNT:" , Tid_dnt)
.Add_str_int("X-Requested-With:" , Tid_x_requested_with)
.Add_str_int("Cookie:" , Tid_cookie)
.Add_str_int("Referer:" , Tid_referer)
.Add_str_int("Content-length:" , Tid_content_length)
.Add_str_int("Content-Type:" , Tid_content_type)
.Add_str_int("Connection:" , Tid_connection)
.Add_str_int("Pragma:" , Tid_pragma)
.Add_str_int("Cache-Control:" , Tid_cache_control)
.Add_str_int("Origin:" , Tid_origin)
, Tid_origin = 17, Tid_accept_charset = 188, Tid_upgrade_request = 19, Tid_x_host = 20, Tid_x_real_ip = 21;
private static final Btrie_slim_mgr trie = Btrie_slim_mgr.ci_a7()
.Add_str_int("GET" , Tid_get)
.Add_str_int("POST" , Tid_post)
.Add_str_int("Host:" , Tid_host)
.Add_str_int("User-Agent:" , Tid_user_agent)
.Add_str_int("Accept:" , Tid_accept)
.Add_str_int("Accept-Language:" , Tid_accept_language)
.Add_str_int("Accept-Encoding:" , Tid_accept_encoding)
.Add_str_int("Accept-Charset:" , Tid_accept_charset)
.Add_str_int("DNT:" , Tid_dnt)
.Add_str_int("X-Requested-With:" , Tid_x_requested_with)
.Add_str_int("Cookie:" , Tid_cookie)
.Add_str_int("Referer:" , Tid_referer)
.Add_str_int("Content-length:" , Tid_content_length)
.Add_str_int("Content-Type:" , Tid_content_type)
.Add_str_int("Connection:" , Tid_connection)
.Add_str_int("Pragma:" , Tid_pragma)
.Add_str_int("Cache-Control:" , Tid_cache_control)
.Add_str_int("Origin:" , Tid_origin)
.Add_str_int("Upgrade-Insecure-Requests:" , Tid_upgrade_request)
.Add_str_int("X-Host:" , Tid_x_host)
.Add_str_int("X-Real-IP:" , Tid_x_real_ip)
;
private static final byte[] Tkn_boundary = Bry_.new_a7("boundary="), Tkn_content_type_boundary_end = Bry_.new_a7("--")
private static final byte[] Tkn_boundary = Bry_.new_a7("boundary="), Tkn_content_type_boundary_end = Bry_.new_a7("--")
, Tkn_content_disposition = Bry_.new_a7("Content-Disposition:"), Tkn_form_data = Bry_.new_a7("form-data;")
, Tkn_name = Bry_.new_a7("name=")
;

View File

@ -16,7 +16,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
package gplx.core.net; import gplx.*; import gplx.core.*;
import org.junit.*; import gplx.core.tests.*;
public class Http_request_parser_tst {
@Before public void init() {fxt.Clear();} private final Http_request_parser_fxt fxt = new Http_request_parser_fxt();
@Before public void init() {fxt.Clear();} private final Http_request_parser_fxt fxt = new Http_request_parser_fxt();
@Test public void Type_post() {
fxt.Test_type_post("POST /url HTTP/1.1", Http_request_itm.Type_post, "/url", "HTTP/1.1");
}
@ -48,11 +48,14 @@ public class Http_request_parser_tst {
@Test public void Type_accept_charset() {
fxt.Test_ignore("Accept-Charset: ISO-8859-1,utf-8;q=0.7");
}
@Test public void Nginx() {// PURPOSE: support http headers from nginx; ISSUE#:255
fxt.Test_ignore("Upgrade-Insecure-Requests: test1; X-Host: test2; X-Real-IP: test3;");
}
}
class Http_request_parser_fxt {
private final Http_request_parser parser;
private final Http_client_rdr client_rdr = Http_client_rdr_.new_mem();
private final Http_server_wtr__mock server_wtr = new Http_server_wtr__mock();
private final Http_request_parser parser;
private final Http_client_rdr client_rdr = Http_client_rdr_.new_mem();
private final Http_server_wtr__mock server_wtr = new Http_server_wtr__mock();
public Http_request_parser_fxt() {
this.parser = new Http_request_parser(server_wtr, false);
}