gon2gon2 / webproxy-jungle

0 stars 0 forks source link

<p> 태그가 렌더링 되지 않고 plaintext로 나타나는 버그 #1

Closed gon2gon2 closed 2 years ago

gon2gon2 commented 2 years ago

expected result

image

In my case

image

/*
 * adder.c - a minimal CGI program that adds two numbers together
 */
/* $begin adder */
#include "../csapp.h"

int main(){
    char *buf, *p;
    char arg1[MAXLINE], arg2[MAXLINE], content[MAXLINE];
    int n1=0, n2=0;

    /* read environmental variable QUERY_STRING */
    if((buf = getenv("QUERY_STRING")) != NULL){
        p = strchr(buf, '&'); // p is the pointer for "&"
        *p = '\0';            // sperate into two array
        strcpy(arg1, buf);    // copy string until null character found(added at line 15)
        strcpy(arg2, p+1);    
        n1 = atoi(arg1);      // atoi: string to number
        n2 = atoi(arg2);
    }

    sprintf(content, "QUERY_STRING=%s&%s\r\n", buf,p+1);  
    sprintf(content, "%sWelcome to add.com: ", content);
    sprintf(content, "%sTHE Internet addition portal. \r\n<p>", content);
    sprintf(content, "%sThe answer is: %d + %d = %d\r\n</p>", content, n1, n2, n1+n2);  
    sprintf(content, "%sThanks for visiting!\r\n", content);

    printf("Connection: close\r\n");
    printf("Content-length: %d\r\n", (int)strlen(content));
    printf("Conten-type: text/html\r\n\r\n");
    printf("%s", content);  
    fflush(stdout);

    exit(0);
}

다른 점

  1. welcometo 부분
  2. p태그 밑에서 두번째만
gon2gon2 commented 2 years ago

알고보니 header의 content-type에 t가 빠져있었다. 헤더의 중요성을 알게 됐다