diff options
| author | lishu <[email protected]> | 2019-11-29 10:31:59 +0800 |
|---|---|---|
| committer | lishu <[email protected]> | 2019-11-29 10:31:59 +0800 |
| commit | eafdfe55074148a44671e0f0002665c3980b2a56 (patch) | |
| tree | bc8a90d9a18f9e019886dd360c034550d4ccfd1e /src | |
| parent | 62bb88086ea094818b6e13ce6c8c4c4dd6408deb (diff) | |
memory
Diffstat (limited to 'src')
| -rw-r--r-- | src/HTTP_Parser.c | 157 | ||||
| -rw-r--r-- | src/http.h | 1 |
2 files changed, 6 insertions, 152 deletions
diff --git a/src/HTTP_Parser.c b/src/HTTP_Parser.c index 6a4384a..3680cb5 100644 --- a/src/HTTP_Parser.c +++ b/src/HTTP_Parser.c @@ -131,158 +131,11 @@ int http_host_parser(const char* buf, uint32 buflen, int http_dir, char** host) free(host_field); host_field = NULL; } - return rec; -} - -/*http_host_parser_test Э��ʶ������,host��������*/ -static const char * http_request = - "POST /gen_204 HTTP/1.1\r\n" - "Host: www.google.com\r\n" - "Connection: close\r\n" - "Content-Length: 0\r\n" - "Origin: https://www.google.com\r\n" - "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36\r\n" - "Content-Type: text/plain;charset=UTF-8\r\n" - "Accept: */*\r\n" - "X-Client-Data: CJG2yQEIorbJAQjEtskBCKmdygEI2J3KAQjZncoBCKijygEY+aXKAQ==\r\n" - "Referer: https://www.google.com/\r\n" - "Accept-Encoding: gzip, deflate\r\n" - "Accept-Language: zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7\r\n"; - -/*http_host_parser_test Э��ʶ������,��host�ֶ�*/ -static const char * http_request_no_host = - "POST /gen_204 HTTP/1.1\r\n" - "Connection: close\r\n" - "Content-Length: 0\r\n" - "Origin: https://www.google.com\r\n" - "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36\r\n" - "Content-Type: text/plain;charset=UTF-8\r\n" - "Accept: */*\r\n" - "X-Client-Data: CJG2yQEIorbJAQjEtskBCKmdygEI2J3KAQjZncoBCKijygEY+aXKAQ==\r\n" - "Referer: https://www.google.com/\r\n" - "Accept-Encoding: gzip, deflate\r\n" - "Accept-Language: zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7\r\n"; - -/*http_host_parser_test Э��ʶ������*/ -static const char * http_response = - "HTTP/1.1 200 OK\r\nAccept-Ranges: bytes\r\nVary: Accept-Encoding\r\nContent-Type: text/javascript; charset=UTF-8\r\nContent-Length: 4064\r\nAge: 8963\r\n"; - -/*http_host_parser_test Э��ʶ��������host����ʧ�ܣ���֧��\r*/ -static const char * http_request_CR = - "POST /gen_204 HTTP/1.1\r" - "Host: www.google.com\r" - "Connection: close\r" - "Content-Length: 0\r" - "Origin: https://www.google.com\r" - "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36\r\n" - "Content-Type: text/plain;charset=UTF-8\r"; - -/*http_host_parser_test Э��ʶ������������ʧ��*/ -static const char * http_reponse_CR = - "HTTP/1.1 200 OK\r" - "Accept-Ranges: bytes\r" - "Vary: Accept-Encoding\r\nContent-Type: text/javascript; charset=UTF-8\r\nContent-Length: 4064\r\nAge: 8963\r\n"; - -/*/*http_host_parser_test Э��ʶ���������������hostΪclose����֧�ִ����*/ -static const char * http_request_LF = - "POST /gen_204 HTTP/1.1\n" - "host: \n" - "Connection: close\n" - "Content-Length: 0\n" - "Origin: https://www.google.com\n"; - -/*http_host_parser_test Э��ʶ������,host��������*/ -static const char * http_request_SPACE = - "POST /gen_204 HTTP/1.1\r\n" - "HOST: www. google.com \r\n"; - -/*http_host_parser_test Э��ʶ������,host��������*/ -static const char * http_request_incpomplete = - "POST /gen_204 HTTP/1.1\n" - "Host: www.googl"; - -/*http_host_parser_test Э��ʶ������,host��������*/ -static const char * http_request_with_body = - "POST /gen_204 HTTP/1.1\r\n" - "Host: www.google.com\r\n" - "Connection: close\r\n" - "Content-Length: 0\r\n" - "Origin: https://www.google.com\r\n" - "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36\r\n" - "Content-Type: text/plain;charset=UTF-8\r\n" - "Accept: */*\r\n" - "X-Client-Data: CJG2yQEIorbJAQjEtskBCKmdygEI2J3KAQjZncoBCKijygEY+aXKAQ==\r\n" - "Referer: https://www.google.com/\r\n" - "Accept-Encoding: gzip, deflate\r\n" - "Accept-Language: zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7\r\n" - "\r\n" - "abcdjhjkhdlaks"; - -/*http_host_parser_test Э��ʶ������,host��������*/ -static const char * http_request_space_start = - "\r \nPOST /gen_204 HTTP/1.1\r\n" - "Host: www.google.com\r\n" - "Connection: close\r\n" - "Content-Length: 0\r\n" - "Origin: https://www.google.com\r\n" - "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36\r\n" - "Content-Type: text/plain;charset=UTF-8\r\n" - "Accept: */*\r\n" - "X-Client-Data: CJG2yQEIorbJAQjEtskBCKmdygEI2J3KAQjZncoBCKijygEY+aXKAQ==\r\n" - "Referer: https://www.google.com/\r\n" - "Accept-Encoding: gzip, deflate\r\n" - "Accept-Language: zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7\r\n" - "\r\n" - "abcdjhjkhdlaks"; - - -void http_host_parser_test(const char* test_buf, int test_buf_dir) -{ - char* host = NULL; - uint32 hostlen = 0; - int rec = -1; - - /*�ж��Ƿ���httpЭ������*/ - rec = http_host_parser((const char*)test_buf, (uint32)strlen(test_buf), test_buf_dir, NULL); - if(-1==rec) - { - printf("not http data\n"); - } - else if(0==rec) - { - printf("is http data\n"); - } - - /*�ж��Ƿ���httpЭ�����ݣ�����ȡhost�ֶ�����*/ - rec = http_host_parser((const char*)test_buf, (uint32)strlen(test_buf), test_buf_dir, &host); - if(-1==rec) - { - printf("not http data\n"); - } - else if(0<=rec) - { - printf("is http data\n"); - if(0<rec) - { - printf("HOST: %.*s\n", (int)rec, host); - } + if(NULL!=parser) + { + free(parser); + parser = NULL; } - printf("http_host_parser_test end!!!!!!!!!!!!!!!!!!!!!!!!!\n\n"); + return rec; } -void http_test() -{ - /*http_host_parser_test����*/ - /* - http_host_parser_test(http_request, DIR_C2S); - http_host_parser_test(http_request_no_host, DIR_C2S); - http_host_parser_test(http_response, DIR_S2C); - http_host_parser_test(http_request_CR, DIR_C2S); - http_host_parser_test(http_reponse_CR, DIR_S2C); - http_host_parser_test(http_request_LF, DIR_C2S); - http_host_parser_test(http_request_SPACE, DIR_C2S); - http_host_parser_test(http_request_incpomplete, DIR_C2S); - http_host_parser_test(http_request_with_body, DIR_C2S); - http_host_parser_test(http_request_space_start, DIR_C2S); - */ -} @@ -247,6 +247,7 @@ int is_absolute_uri(void* app_info); int http_host_parser(const char* buf, uint32 buflen, int http_dir, char** host); + #ifdef __cplusplus } #endif |
