Language
C
Compiler
gcc 12.1.0
Options
Warnings
Optimization
C99
no pedantic
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char url[] = "https://objects.githubusercontent.com/github-production-release-asset-2e65be/21611723/f7cfd480-a7ea-11ea-852c-52df94ee4644?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20220728%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20220728T104250Z&X-Amz-Expires=300&X-Amz-Signature=7dbec7d58625f02f8b4dba25f74a9b3cc688184704c228f256a6a855ab41f19c&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=21611723&response-content-disposition=attachment%3B%20filename%3DQuasar.v1.4.0.zip&response-content-type=application%2Foctet-stream";
void parser(char * result, char * host, char * endpoint)
{
int i=0,j=0;
int size = strlen(result);
if (strstr(result , "https://"))
{
for (i=8; i < size; i++)
{
if (result[i] == '/') break;
host[j] = result[i];
j++;
}
host[j] = '\0';
j=0;
while ( i < strlen(result))
{
endpoint[j] = result[i];
i++,j++;
}
endpoint[j] = '\0';
}
}
int main(void) {
char host[1024], endpoint[1024];
parser(url, host, endpoint);
char * request = (char *)malloc(8192);
sprintf(request , "%s %s HTTP/1.1\n%s\r\n\r\n%s", "GET", endpoint, "","");
printf("host: \"%s\"\n", host);
printf("endpoint: \"%s\"\n", endpoint);
puts("request:");
fputs(request, stdout);
return 0;
}
$ gcc prog.c -Wall -Wextra -std=gnu11
host: "objects.githubusercontent.com"
endpoint: "/github-production-release-asset-2e65be/21611723/f7cfd480-a7ea-11ea-852c-52df94ee4644?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20220728%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20220728T104250Z&X-Amz-Expires=300&X-Amz-Signature=7dbec7d58625f02f8b4dba25f74a9b3cc688184704c228f256a6a855ab41f19c&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=21611723&response-content-disposition=attachment%3B%20filename%3DQuasar.v1.4.0.zip&response-content-type=application%2Foctet-stream"
request:
GET /github-production-release-asset-2e65be/21611723/f7cfd480-a7ea-11ea-852c-52df94ee4644?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20220728%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20220728T104250Z&X-Amz-Expires=300&X-Amz-Signature=7dbec7d58625f02f8b4dba25f74a9b3cc688184704c228f256a6a855ab41f19c&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=21611723&response-content-disposition=attachment%3B%20filename%3DQuasar.v1.4.0.zip&response-content-type=application%2Foctet-stream HTTP/1.1
Exit Code:
0