示例#1
0
文件: cache.c 项目: ni-webtech/http
static void cacheAtClient(HttpConn *conn)
{
    HttpTx      *tx;
    HttpCache   *cache;
    cchar       *value;

    tx = conn->tx;
    cache = conn->tx->cache;

    if (!mprLookupKey(tx->headers, "Cache-Control")) {
        if ((value = mprLookupKey(conn->tx->headers, "Cache-Control")) != 0) {
            if (strstr(value, "max-age") == 0) {
                httpAppendHeader(conn, "Cache-Control", "max-age=%d", cache->clientLifespan / MPR_TICKS_PER_SEC);
            }
        } else {
            httpAddHeader(conn, "Cache-Control", "max-age=%d", cache->clientLifespan / MPR_TICKS_PER_SEC);
        }
#if UNUSED && KEEP
        {
            /* Old HTTP/1.0 clients don't understand Cache-Control */
            struct tm   tm;
            mprDecodeUniversalTime(&tm, conn->http->now + (expires * MPR_TICKS_PER_SEC));
            httpAddHeader(conn, "Expires", "%s", mprFormatTime(MPR_HTTP_DATE, &tm));
        }
#endif
    }
}
示例#2
0
文件: testTime.c 项目: doghell/mpr-3
static void testZones(MprTestGroup *gp)
{
    MprTime     now;
    struct  tm  tm;

    now = mprGetTime(gp);
    mprDecodeLocalTime(gp, &tm, now);
    mprDecodeUniversalTime(gp, &tm, now);
}
示例#3
0
static void testZones(MprTestGroup *gp)
{
    MprTime     now;
    struct  tm  tm;

    /* TODO - need some tests here */
    now = mprGetTime();
    mprDecodeLocalTime(&tm, now);
    mprDecodeUniversalTime(&tm, now);
}
示例#4
0
文件: misc.c 项目: doghell/appweb-3
/*
 *  Build an ASCII time string.  If sbuf is NULL we use the current time, else we use the last modified time of sbuf
 */
char *maGetDateString(MprCtx ctx, MprPath *sbuf)
{
    MprTime     when;
    struct tm   tm;

    if (sbuf == 0) {
        when = mprGetTime(ctx);
    } else {
        when = (MprTime) sbuf->mtime * MPR_TICKS_PER_SEC;
    }
    mprDecodeUniversalTime(ctx, &tm, when);
    return mprFormatTime(ctx, MPR_HTTP_DATE, &tm);
}
示例#5
0
文件: ejsCgi.c 项目: doghell/appweb-3
/*
 *  Get a date string. If sbuf is non-null, get the modified time of that file. If null, then get the current system time.
 */
static char *makeDateString(MprPath *sbuf)
{
    MprTime     when;
    struct tm   tm;

    if (sbuf == 0) {
        when = mprGetTime(mpr);
    } else {
        when = (MprTime) sbuf->mtime * MPR_TICKS_PER_SEC;
    }

    mprDecodeUniversalTime(mpr, &tm, when);
    return mprFormatTime(mpr, MPR_RFC_DATE, &tm);
}
示例#6
0
文件: log.c 项目: gamman/appweb-3
/*
 *  Called to rotate the access log
 */
void maRotateAccessLog(MaHost *host)
{
    MprPath         info;
    struct tm       tm;
    MprTime         when;
    char            bak[MPR_MAX_FNAME];

    if (mprGetPathInfo(host, host->logPath, &info) == 0) {
        when = mprGetTime(host);
        mprDecodeUniversalTime(host, &tm, when);
        mprSprintf(bak, sizeof(bak), "%s-%02d-%02d-%02d-%02d:%02d:%02d", host->logPath, 
            tm.tm_mon, tm.tm_mday, tm.tm_year, tm.tm_hour, tm.tm_min, tm.tm_sec);
        mprFree(host->accessLog);
        rename(host->logPath, bak);
        unlink(host->logPath);
        host->accessLog = mprOpen(host, host->logPath, O_CREAT | O_TRUNC | O_WRONLY | O_TEXT, 0664);
    }
}
示例#7
0
文件: ejsCgi.c 项目: doghell/appweb-3
/*
 *  Add a response cookie
 */
static void setCookie(void *handle, cchar *name, cchar *value, cchar *path, cchar *cookieDomain, int lifetime, bool isSecure)
{
    struct tm   tm;
    cchar       *userAgent, *hostName;
    char        dateStr[64], *cp, *expiresAtt, *expires, *domainAtt, *domain, *secure;

    if (path == 0) {
        path = "/";
    }

    userAgent = getHeader(handle, "HTTP_USER_AGENT");
    hostName = getHeader(handle, "HTTP_HOST");

    /*
     *  Fix for Safari and Bonjour addresses with a trailing ".". Safari discards cookies without a domain specifier
     *  or with a domain that includes a trailing ".". Solution: include an explicit domain and trim the trailing ".".
     *
     *   User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-us)
     *       AppleWebKit/530.0+ (KHTML, like Gecko) Version/3.1.2 Safari/525.20.1
     */
    if (cookieDomain == 0 && userAgent && strstr(userAgent, "AppleWebKit") != 0) {
        domain = mprStrdup(mpr, hostName);
        if ((cp = strchr(domain, ':')) != 0) {
            *cp = '\0';
        }
        if (*domain && domain[strlen(domain) - 1] == '.') {
            domain[strlen(domain) - 1] = '\0';
        } else {
            domain = 0;
        }
    } else {
        domain = 0;
    }
    if (domain) {
        domainAtt = "; domain=";
    } else {
        domainAtt = "";
    }
    if (lifetime > 0) {
        mprDecodeUniversalTime(mpr, &tm, mprGetTime(mpr) + (lifetime * MPR_TICKS_PER_SEC));
        mprFormatTime(mpr, MPR_HTTP_DATE, &tm);
        expiresAtt = "; expires=";
        expires = dateStr;

    } else {
        expires = expiresAtt = "";
    }
    if (isSecure) {
        secure = "; secure";
    } else {
        secure = ";";
    }

    /*
     *  Allow multiple cookie headers. Even if the same name. Later definitions take precedence
     */
    setHeader(handle, 1, "Set-Cookie",
              mprStrcat(mpr, -1, name, "=", value, "; path=", path, domainAtt, domain, expiresAtt, expires, secure, NULL));

    setHeader(handle, 0, "Cache-control", "no-cache=\"set-cookie\"");
}