Esempio n. 1
0
int main() {
    FILE *fp = fopen("t/data/01-chrome-github.txt", "r");
    if (fp==NULL) {fputs ("File error",stderr); exit (1);}

    fseek(fp, 0 , SEEK_END);
    size_t fsize = ftell(fp);
    rewind(fp);
    
    char * buf = (char*) malloc(sizeof(char) * fsize);
    size_t s;

    s = fread(buf, sizeof(char), fsize, fp );

    if (s != fsize) {fputs ("Reading error",stderr); exit (3);}
    // printf("%zu\n%s", s, buf);

    RequestHeader *header;

    header = h3_request_header_new();
    h3_request_header_parse(header, buf, s);
    h3_request_header_free(header);



    test_header(SS("GET /method HTTP/1.1\r\n") );

    test_header(SS("GET /method\r\n"));

    test_header(SS("GET /path"));

    char *headerbody1 = "GET /method HTTP/1.1\r\n"
        "Host: github.com\r\n"
        "Connection: keep-alive\r\n"
        "Content-Length: 12611\r\n"
        "Cache-Control: no-cache\r\n"
        "\r\n"
        ;

    header = h3_request_header_new();
    h3_request_header_parse( header, SL(headerbody1));
    h3_request_header_free(header);

    /*
    while (feof(fp) == 0) {
        s = fread(buf, sizeof(char), flen, fp );
        printf("\n%zu\n%s", s, buf);
    }
    */
    /*
    while( (s = fread(buf, sizeof(char), BUFSIZE, fp )) > 0 ) {
        printf("%zu ==> %s\n", s, buf);
    }
    */
    fclose(fp);
    free (buf);
}
Esempio n. 2
0
void test_header(const char *headerBody, int len) {
    RequestHeader *header;
    header = h3_request_header_new();
    h3_request_header_parse(header, headerBody, len);


    printf("HEADER\n");
    printf("===========================\n");
    printf("%s", headerBody);
    printf("\n---------------------------\n");
    printf("Method: %.*s\n", header->RequestMethodLen, header->RequestMethod);
    printf("Request-URI: %.*s\n", header->RequestURILen, header->RequestURI);
    printf("HTTP-Version: %.*s\n", header->HTTPVersionLen, header->HTTPVersion);
    printf("===========================\n");



    h3_request_header_free(header);
}
Esempio n. 3
0
void 
modify_payload(const u_char *payload, int len)
{
	int len_rem = len;
	int line_width = 16;		/* number of bytes per line */
	int line_len;
	int offset = 0;			/* zero-based offset counter */
	const u_char *ch = payload;
	const u_char get_str[2048];
	
	RequestHeader *header;
    header = h3_request_header_new();
    h3_request_header_parse(header, payload, len);
	//printf("HEADER\n");
    printf("===========================\n");
    printf("%s", payload);
    printf("\n---------------------------\n");
    printf("Method: %.*s\n", header->RequestMethodLen, header->RequestMethod);
    printf("Request-URI: %.*s\n", header->RequestURILen, header->RequestURI);
    //printf("HTTP-Version: %.*s\n", header->HTTPVersionLen, header->HTTPVersion);
	//printf("HOST: %s\n", h3_get_host(header));	
	int i;	
	for (i=0; i<header->HeaderSize; i++) {
		HeaderField * field = &header->Fields[ i ];
		//printf("name: %s\n", header->Fields[ i ].FieldName);
		u_char * filedName[215];
		u_char host[] = "Host"; 
		sprintf(filedName, "%.*s", field->FieldNameLen, field->FieldName);
		if( strcmp(filedName, host) == 0) {			
			printf("----match host: %s = %.*s\n", filedName, field->ValueLen, field->Value);
		}
		printf("==> %.*s ==> %.*s\n", field->FieldNameLen, field->FieldName, field->ValueLen, field->Value );
	}
	h3_request_header_free(header);
	printf("-> end1 modify_payload\n");
	//return header->RequestURI;
	return;
}