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,7 +18,10 @@ import gplx.core.primitives.*; import gplx.core.btries.*;
public class Http_request_parser { public class Http_request_parser {
private boolean dnt; private boolean dnt;
private int type, content_length; 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 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 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 Http_server_wtr server_wtr; private final boolean log;
@ -26,8 +29,12 @@ public class Http_request_parser {
public void Clear() { public void Clear() {
this.dnt = false; this.dnt = false;
this.type = this.content_length = 0; 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.url = this.protocol = this.host = this.user_agent = this.accept
= this.referer = this.content_type = this.content_type_boundary = this.connection = this.pragma = this.cache_control = this.origin = null; = 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; this.post_data_hash = null;
} }
public Http_request_itm Parse(Http_client_rdr rdr) { 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_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_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_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; case Tid_accept_charset: break;
default: throw Err_.new_unhandled(tid); default: throw Err_.new_unhandled(tid);
} }
@ -146,7 +156,7 @@ public class Http_request_parser {
private String To_str() {return Make_request_itm().To_str(tmp_bfr, Bool_.N);} 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 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_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; , 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() private static final Btrie_slim_mgr trie = Btrie_slim_mgr.ci_a7()
.Add_str_int("GET" , Tid_get) .Add_str_int("GET" , Tid_get)
.Add_str_int("POST" , Tid_post) .Add_str_int("POST" , Tid_post)
@ -166,6 +176,9 @@ public class Http_request_parser {
.Add_str_int("Pragma:" , Tid_pragma) .Add_str_int("Pragma:" , Tid_pragma)
.Add_str_int("Cache-Control:" , Tid_cache_control) .Add_str_int("Cache-Control:" , Tid_cache_control)
.Add_str_int("Origin:" , Tid_origin) .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_content_disposition = Bry_.new_a7("Content-Disposition:"), Tkn_form_data = Bry_.new_a7("form-data;")

View File

@ -48,6 +48,9 @@ public class Http_request_parser_tst {
@Test public void Type_accept_charset() { @Test public void Type_accept_charset() {
fxt.Test_ignore("Accept-Charset: ISO-8859-1,utf-8;q=0.7"); 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 { class Http_request_parser_fxt {
private final Http_request_parser parser; private final Http_request_parser parser;