sprintf(line_buffer, "Accept: %s, %s, %s, %s, %s, */*" CRLF, IMAGE_GIF, IMAGE_XBM, IMAGE_JPG, IMAGE_PJPG, IMAGE_PNG);
sprintf(line_buffer, "Accept: %s, %s, %s, %s, %s, %s, %s, */*" CRLF, TEXT_HTML, TEXT_XML, IMAGE_PNG, IMAGE_GIF, IMAGE_XBM, IMAGE_JPG, IMAGE_PJPG);
net_build_http_request (URL_Struct * URL_s,            FO_Present_Types format_out,            HTTPConData *cd,            MWContext *window_id,            char          ** command){    Bool http1=cd->send_http1;    char *proxy_server=(cd->use_proxy_tunnel ? NULL : cd->proxy_server);    Bool posting=cd->posting;    char line_buffer[4096];  /* buffer */    char *auth;         /* authorization header string */    size_t csize;        /* size of command */    const char *tempURL=NULL;    char *proxyServer=NULL;    int tmpSize = 0;            /* begin the request */    switch(URL_s->method) {        case URL_MKDIR_METHOD:#define MKDIR_WORD "MKDIR "            BlockAllocCopy(*command, MKDIR_WORD, 5);            csize = sizeof(MKDIR_WORD)-1;            break;        case URL_DELETE_METHOD:#define DELETE_WORD "DELETE "#define RMDIR_WORD "RMDIR "            if(URL_s->is_directory) {                BlockAllocCopy(*command, RMDIR_WORD, 6);                csize = sizeof(RMDIR_WORD)-1;            } else {                BlockAllocCopy(*command, DELETE_WORD, 7);                csize = sizeof(DELETE_WORD)-1;            }            break;        case URL_POST_METHOD:#define POST_WORD "POST "            BlockAllocCopy(*command, POST_WORD, 5);            csize = sizeof(POST_WORD)-1;            break;        case URL_PUT_METHOD:#define PUT_WORD "PUT "            BlockAllocCopy(*command, PUT_WORD, 4);            csize = sizeof(PUT_WORD)-1;            break;        case URL_HEAD_METHOD:#define HEAD_WORD "HEAD "            BlockAllocCopy(*command, HEAD_WORD, 5);            csize = sizeof(HEAD_WORD)-1;            break;              case URL_INDEX_METHOD:#define INDEX_WORD "INDEX "            BlockAllocCopy(*command, INDEX_WORD, 6);            csize = sizeof(INDEX_WORD)-1;            break;        case URL_MOVE_METHOD:#define MOVE_WORD "MOVE "            BlockAllocCopy(*command, MOVE_WORD, 5);            csize = sizeof(MOVE_WORD)-1;            break;        case URL_COPY_METHOD:#define COPY_WORD "COPY "            BlockAllocCopy(*command, COPY_WORD, 5);            csize = sizeof(COPY_WORD)-1;            break;        default:            PR_ASSERT(0);            /* fall through to GET */        case URL_GET_METHOD:#define GET_WORD "GET "            BlockAllocCopy(*command, GET_WORD, 4);            csize = sizeof(GET_WORD)-1;            break;        case URL_GETPROPERTIES_METHOD:#define GETPROPERTIES_WORD "GETPROPERTIES "            BlockAllocCopy(*command, GETPROPERTIES_WORD, 14);            csize = sizeof(GETPROPERTIES_WORD)-1;            break;    } /* End method switch */    /* if we are using a proxy gateway copy in the entire URL     * minus the hash mark */    if(proxy_server) {        char *url_minus_hash = NET_ParseURL(URL_s->address,               GET_PROTOCOL_PART             | GET_USERNAME_PART            | GET_PASSWORD_PART            | GET_HOST_PART             | GET_PATH_PART             | GET_SEARCH_PART);        if(url_minus_hash) {            tmpSize = PL_strlen(url_minus_hash);            BlockAllocCat(*command, (size_t) csize, url_minus_hash, tmpSize);            csize += tmpSize;            PR_Free(url_minus_hash);        }    } else {        /* else use just the path and search stuff */        char *path = NET_ParseURL(URL_s->address, GET_PATH_PART | GET_SEARCH_PART);        tmpSize = PL_strlen(path);        BlockAllocCat(*command, csize, path, tmpSize);        csize += tmpSize;        PR_Free(path);    }    if(http1) {        const char *ver = VERSION_STRING_ONE_ONE;        if (ONE_POINT_ONE != DEFAULT_VERSION)            ver = VERSION_STRING_ONE_ZERO;        BlockAllocCat(*command, csize, " ", 1);        csize += 1;        PR_ASSERT(VERSION_STRING_LEN == PL_strlen(ver));        BlockAllocCat(*command, csize, ver, VERSION_STRING_LEN);        csize += VERSION_STRING_LEN;        /* finish the line */        BlockAllocCat(*command, csize, CRLF, 2); /* CR LF, as in rfc 977 */        csize += 2;        if ((URL_s->etag) && (URL_s->force_reload != NET_SUPER_RELOAD))        {            /* add the If-None-Match header */            PL_strcpy(line_buffer, "If-None-Match: \"");            tmpSize = PL_strlen(line_buffer);            BlockAllocCat(*command, csize,                line_buffer, tmpSize);            csize += tmpSize;            tmpSize = PL_strlen(URL_s->etag);            BlockAllocCat(*command, csize,                 URL_s->etag,                tmpSize);            csize += tmpSize;            /* Closing " */            BlockAllocCat(*command, csize,                "\"",                1);            csize += 1;            BlockAllocCat(*command, csize, CRLF, 2);            csize += 2;        }        if(URL_s->last_modified && URL_s->force_reload != NET_SUPER_RELOAD)        {            /* add if modified since             *             * right now this is being added even if the server sent pragma: no-cache             * I'm not sure if this is the right thing to do but it seems             * very efficient since we can still use the cache.             */            /* add tmp character storage for strings in order for assert             * to work properly in debug compile.             * IBM compiler does not put "\" to make " work properly.             */#ifndef AIX            char *tmp_str = "http";#endif            {                /* A conversion from time_t to NSPR's int64 is needed in order to                 * use the NSPR time functions.  URL_Struct should really be changed                 * to use the NSPR time type instead of time_t.                 */                PRTime   timeInSec;                PRTime timeInUSec;                PRTime   secToUSec;                PRExplodedTime expandedTime;                LL_I2L(timeInSec, URL_s->last_modified);                LL_I2L(secToUSec, PR_USEC_PER_SEC);                LL_MUL(timeInUSec, timeInSec, secToUSec);                PR_ExplodeTime(timeInUSec, PR_GMTParameters, &expandedTime);                PR_FormatTimeUSEnglish(line_buffer, 400,                                      "If-Modified-Since: %a, %d %b %Y %H:%M:%S GMT",                                      &expandedTime);            }            /* must not be zero for http URL's              * or else I screwed up the cache logic              */#ifndef AIX            PR_ASSERT(PL_strncasecmp(URL_s->address, tmp_str, 4)                || URL_s->real_content_length > 0);#endif            if(URL_s->real_content_length)                sprintf(&line_buffer[PL_strlen(line_buffer)],                     "; length=%ld" CRLF,                    URL_s->real_content_length);            tmpSize = PL_strlen(line_buffer);            BlockAllocCat(*command, csize, line_buffer, tmpSize);            csize += tmpSize;            /* reset the expires since we will want to             * either get a new one from the server or             * set it to zero             */            URL_s->expires = 0;        } /* end if last_modified */        if(URL_s->http_headers) {  /* use headers that were passed in */            tmpSize = PL_strlen(URL_s->http_headers);            BlockAllocCat(*command, csize, URL_s->http_headers, tmpSize);            csize += tmpSize;        } else {            /* For MOVE method. This contains the destination uri name */            int meth=URL_s->method;            if(URL_s->destination                     && (*(URL_s->destination) != '\0')                    && ( (meth == URL_MOVE_METHOD)                        || (meth == URL_COPY_METHOD) )            ){                if(meth == URL_MOVE_METHOD) {                    sprintf(line_buffer, "New-uri: %s", URL_s->destination);                    tmpSize = PL_strlen(line_buffer);                    BlockAllocCat(*command, csize, line_buffer, tmpSize);                    csize+=tmpSize;                } else if(meth == URL_COPY_METHOD) {                    ;/* some http copy syntax */                }                BlockAllocCat(*command, csize, CRLF, 2);                csize += 2;            }            /* sendRefererHeader is set in NET_SetSendRefererHeaderPref in mkhttp.c.              This condition is set via a javascript pref and was implemented to              settle some privacy/security issue */            /* NET_SupressRefererForAnonymity is true on the first call after entering             or leaving anonymous mode and false all other times.  Note that this             function has a side effect of changing its own state (so that future             calls to it return false until another mode change occurs).  For this             reason it must appear first in the if-statement below to make sure it             gets called even if sendReferHeader is false */            if(!NET_SupressRefererForAnonymity(window_id) && sendRefererHeader)            {                int url_type = NET_URL_Type(URL_s->referer);                char *newReferer=NULL;                /* Don't allow these url types to send the referer field. */                if(URL_s->referer                     && url_type != MAILBOX_TYPE_URL                    && url_type != IMAP_TYPE_URL                    && url_type != FILE_TYPE_URL)                {                    char *colon=NULL, *refToSend=NULL;                    TRACEMSG(("Sending referer field"));                    PL_strcpy(line_buffer, "Referer: ");                    tmpSize = PL_strlen(line_buffer);                    BlockAllocCat(*command, csize, line_buffer, tmpSize);                    csize += tmpSize;                              /* The URL_s->referer can contain a username and password as it draws                     * this data from the session history. The session history can contain                      * the username and password if the user types them into the location                     * field, like so: http://username:password@www.here.com. We strip out                     * the username and password here so this info isn't revealed in the                      * referer header. */                    colon=PL_strchr(URL_s->referer, ':');                    if(colon                        && *(colon+1) == '/'                        && *(colon+2) == '/'                        && *(colon+3) != '\0')                    {                        char *atSign=NULL;                                    char *path=NULL;                        if( (path=PL_strchr(colon+3, '/')) != 0)                            *path='\0';                        if( (atSign=PL_strchr(colon, '@')) != 0) {                            /* We found a username and/or a password, don't let it through */                            char temp;                            if(path)                                *path='/';                            /* Get the protocol part. */                            temp=*(colon+3);                            *(colon+3)='\0';                            StrAllocCopy(newReferer, URL_s->referer);                            *(colon+3)=temp;                            /* Get the host part. */                            *atSign='\0';                            StrAllocCat(newReferer, atSign+1);                            *atSign='@';                        }                        if(path)                            *path='/';                    } /* End colon */                    refToSend= newReferer ? newReferer : URL_s->referer;                    tmpSize = PL_strlen(refToSend);                    BlockAllocCat(*command,  csize, refToSend, tmpSize);                    csize += tmpSize;                    BlockAllocCat(*command, csize, CRLF, 2);                    csize += 2;                    PR_FREEIF(newReferer);                } /* end URL_s->refrerer */            } /* end supress */            assert (XP_AppCodeName);            assert (XP_AppVersion);            if(!(cd->connection->doNotSendConHdr)) {                if(proxy_server)                    PL_strcpy(line_buffer, "Proxy-Connection: Keep-Alive" CRLF);                else                    PL_strcpy(line_buffer, "Connection: Keep-Alive" CRLF);            }            sprintf (&line_buffer[PL_strlen(line_buffer)],                 "User-Agent: %.100s/%.90s" CRLF,                XP_AppCodeName, XP_AppVersion);            tmpSize = PL_strlen(line_buffer);            BlockAllocCat(*command, csize, line_buffer, tmpSize);            csize += tmpSize;            if(URL_s->force_reload) {                BlockAllocCat(*command, csize, "Pragma: no-cache" CRLF, 18);                csize += 18;            }            if(URL_s->range_header) {#ifndef AIX                char *tmp_str = CRLF;                PR_ASSERT(!PL_strstr(URL_s->range_header, tmp_str));#endif#define REQUEST_RANGE_HEADER "Range: "                tmpSize = PL_strlen(REQUEST_RANGE_HEADER);                BlockAllocCat(*command, csize,                     REQUEST_RANGE_HEADER,                    tmpSize);                csize += tmpSize;                tmpSize = PL_strlen(URL_s->range_header);                BlockAllocCat(*command, csize,                     URL_s->range_header,                    tmpSize);                csize += tmpSize;                BlockAllocCat(*command, csize,                     CRLF, 2);                csize += 2;            } /* end url_s->range_header */#define OLD_RANGE_SUPPORT#ifdef OLD_RANGE_SUPPORT            /* this is here for backwards compatibility with             * the old range spec             * It should be removed before final beta 2             */            if(URL_s->range_header) {#ifndef AIX                char *tmp_str = CRLF;                PR_ASSERT(!PL_strstr(URL_s->range_header, tmp_str));#endif#undef REQUEST_RANGE_HEADER#define REQUEST_RANGE_HEADER "Request-Range: "                tmpSize = PL_strlen(REQUEST_RANGE_HEADER);                BlockAllocCat(*command, csize,                    REQUEST_RANGE_HEADER,                    tmpSize);                csize += tmpSize;                tmpSize = PL_strlen(URL_s->range_header);                BlockAllocCat(*command, csize,                    URL_s->range_header,                    tmpSize);                csize += tmpSize;                BlockAllocCat(*command, csize,                    CRLF, 2);                csize += 2;            } /* end url_s->range_header */#endif            if(1) {                char * host = NET_ParseURL(URL_s->address, GET_HOST_PART);                if(host) {#define HOST_HEADER "Host: "                    BlockAllocCat(*command,                         csize,                          HOST_HEADER,                          sizeof(HOST_HEADER)-1);                    csize += sizeof(HOST_HEADER)-1;                    tmpSize = PL_strlen(host);                    BlockAllocCat(*command, csize, host, tmpSize);                    csize += tmpSize;                    PR_Free(host);                    BlockAllocCat(*command, csize, CRLF, 2);                    csize += 2;                }            }#ifdef SEND_FROM_FIELD            sprintf(line_buffer, "From: %.256s%c%c",                 FE_UsersMailAddress() ? FE_UsersMailAddress() : "unregistered", CR,LF);            tmpSize = PL_strlen(line_buffer);            BlockAllocCat(*command, csize, line_buffer, tmpSize);            csize += tmpSize;#endif /* SEND_FROM_FIELD */            if(CLEAR_CACHE_BIT(format_out) != FO_INTERNAL_IMAGE)            {                /* send Accept: *(slash)* as well as the others */                sprintf(line_buffer, "Accept: %s, %s, %s, %s, %s, */*" CRLF,                     IMAGE_GIF, IMAGE_XBM, IMAGE_JPG, IMAGE_PJPG, IMAGE_PNG);            } else {                sprintf(line_buffer, "Accept: %s, %s, %s, %s, %s" CRLF,                     IMAGE_GIF, IMAGE_XBM, IMAGE_JPG, IMAGE_PJPG, IMAGE_PNG);            }            tmpSize = PL_strlen(line_buffer);            BlockAllocCat(*command, csize, line_buffer, tmpSize);            csize += tmpSize;            /* add Accept-Encoding Header */            sprintf(line_buffer, "Accept-Encoding: %s" CRLF, ENCODING_GZIP2);            tmpSize = PL_strlen(line_buffer);            BlockAllocCat(*command, csize, line_buffer, tmpSize);            csize += tmpSize;#ifdef MOZILLA_CLIENT#define SEND_ACCEPT_LANGUAGE 1#ifdef SEND_ACCEPT_LANGUAGE /* Added by ftang */            {                char *acceptlang = INTL_GetAcceptLanguage();                if((acceptlang != NULL) && ( *acceptlang != '\0') )                {                    sprintf(line_buffer, "Accept-Language: %s" CRLF,                         acceptlang );                    tmpSize = PL_strlen(line_buffer);                    BlockAllocCat(*command, csize, line_buffer, tmpSize);                    csize += tmpSize;                }            }#endif /* SEND_ACCEPT_LANGUAGE */#define SEND_ACCEPT_CHARSET 1#ifdef SEND_ACCEPT_CHARSET  /* Added by bstell */            {                char *acceptCharset = INTL_GetAcceptCharset();                if((acceptCharset != NULL) && ( *acceptCharset != '\0') )                {                    sprintf(line_buffer, "Accept-Charset: %s" CRLF,                         acceptCharset );                    tmpSize = PL_strlen(line_buffer);                    BlockAllocCat(*command, csize, line_buffer, tmpSize);                    csize += tmpSize;                }            }#endif /* SEND_ACCEPT_CHARSET */#endif /* MOZILLA_CLIENT */            /*             * Check if proxy is requiring authorization.             * If NULL, not necessary, or the proxy will return 407 to             * require authorization.             *             */            /* This was hacked in because proxy auth can be required when the Auto-config url             * itself requires authorization. We used to ask for proxy auth only when the proxy was              * input directly into the prefs. Now we check to see if there's a pacurl (if there             * is, there can't be a proxy url simultaneously) use it, otherwise we're using a             * proxy from the prefs.             */            /* Figure out which kind of proxy we're using: PAC or straight proxy.              * DON'T FREE tempURL!!!             */            if ( (tempURL = net_GetPACUrl()) != NULL && (*tempURL) )                proxyServer = NET_ParseURL(tempURL,                                   GET_HOST_PART                                 | GET_PATH_PART                                | GET_USERNAME_PART                                | GET_PASSWORD_PART);            else                 proxyServer = proxy_server;             if (proxyServer &&                    NULL != (auth=NET_BuildProxyAuthString(window_id,                             URL_s,                             proxyServer))            ){                if (tempURL)                    PR_Free(proxyServer);                cd->sent_proxy_auth = TRUE;                sprintf(line_buffer, "Proxy-authorization: %.3840s%c%c", auth, CR, LF);                tmpSize = PL_strlen(line_buffer);                BlockAllocCat(*command, csize, line_buffer, tmpSize);                csize += tmpSize;                TRACEMSG(("HTTP: Sending proxy-authorization: %s", auth));            } else {                TRACEMSG(("HTTP: Not sending proxy authorization (yet)"));            }            /* NET_BuildAuthString will return non-NULL if authorization is             * known to be required for this document.             *             * If NULL is returned authorization is not required or is             * not known to be required yet so we will look for a 401             * return code later on to see if authorization will be             * neccessary             */            if (NULL!=(auth=NET_BuildAuthString(window_id, URL_s)))             {                cd->sent_authorization = TRUE;                tmpSize = PL_strlen(auth);                BlockAllocCat(*command, csize, auth, tmpSize);                csize += tmpSize;                TRACEMSG(("HTTP: Sending authorization: %s", auth));            } else {                TRACEMSG(("HTTP: Not sending authorization (yet)"));            }            if (NULL!=(auth=NET_GetCookie(window_id, URL_s->address)))             {                PL_strcpy(line_buffer, "Cookie: ");                tmpSize = PL_strlen(line_buffer);                BlockAllocCat(*command, csize,                     line_buffer, tmpSize);                        csize += tmpSize;                tmpSize = PL_strlen(auth);                BlockAllocCat(*command, csize, auth, tmpSize);                csize += tmpSize;                BlockAllocCat(*command, csize, CRLF, 2);                csize += 2;                TRACEMSG(("HTTP: Sending Cookie: %s", auth));                PR_Free(auth);            } else {                TRACEMSG(("HTTP: Not sending cookie"));            }        }  /* end of if passed in headers */    }  /* end of if(http1) */    /* end of Get/Post request */    /* Blank line means "end" of headers     * If we are posting WritePostData will     * add the extra line feed for us     */    if(!posting) {        BlockAllocCat(*command, csize, CRLF, 2);         csize += 2;    }    return((unsigned int) csize);}