Embperl
view release on metacpan or search on metacpan
SetHashValueInt (r, r -> pThread -> pHeaderHash, "Content-Length", GetContentLength (r) ) ;
}
r -> bError = 1 ;
return ok ;
}
/* ---------------------------------------------------------------------------- */
/* */
/* SendHttpHeader */
/* */
/* ---------------------------------------------------------------------------- */
int embperl_SendHttpHeader (/*i/o*/ register req * r)
{
epTHX_
char * pCookie = NULL ;
if (r -> Config.nSessionMode & smodeUDatCookie)
pCookie = CreateSessionCookie (r, r -> pApp -> pUserObj, 'u', 1) ;
#ifdef APACHE
if (r -> pApacheReq)
{
SV * pHeader ;
char * p ;
HE * pEntry ;
char * pKey ;
I32 l ;
STRLEN ldummy ;
I32 i;
I32 len;
AV *arr;
SV **svp;
/* loc = 0 => no location header found
* loc = 1 => location header found
* loc = 2 => location header + value found
* loc = 3 => location header + value + status found
*/
I32 loc;
I32 loc_status = 301;
hv_iterinit (r -> pThread -> pHeaderHash) ;
while ((pEntry = hv_iternext (r -> pThread -> pHeaderHash)))
{
pKey = hv_iterkey (pEntry, &l) ;
pHeader = hv_iterval (r -> pThread -> pHeaderHash, pEntry) ;
loc = 0;
if (pHeader && pKey)
{
if (stricmp (pKey, "location") == 0)
loc = 1;
if (stricmp (pKey, "content-type") == 0)
{
p = NULL;
if ( SvROK(pHeader) && SvTYPE(SvRV(pHeader)) == SVt_PVAV )
{
arr = (AV *)SvRV(pHeader);
if (av_len(arr) >= 0)
{
svp = av_fetch(arr, 0, 0);
p = SvPV(*svp, ldummy);
}
}
else
{
p = SvPV(pHeader, ldummy);
}
if (p)
r->pApacheReq->content_type = apr_pstrdup(r->pApacheReq->pool, p);
}
else if (SvROK(pHeader) && SvTYPE(SvRV(pHeader)) == SVt_PVAV )
{
arr = (AV *)SvRV(pHeader);
len = av_len(arr);
for (i = 0; i <= len; i++)
{
svp = av_fetch(arr, i, 0);
if (loc == 2)
{
loc = 3;
loc_status = SvIV(*svp);
break;
}
p = SvPV(*svp, ldummy);
apr_table_add( r->pApacheReq->headers_out, apr_pstrdup(r->pApacheReq->pool, pKey),
apr_pstrdup(r->pApacheReq->pool, p ) );
if (loc == 1)
loc = 2;
}
}
else
{
p = SvPV(pHeader, ldummy);
apr_table_set(r -> pApacheReq->headers_out, apr_pstrdup(r -> pApacheReq->pool, pKey), apr_pstrdup(r -> pApacheReq->pool, p)) ;
if (loc == 1) loc = 2;
}
if (loc >= 2) r->pApacheReq->status = loc_status;
}
}
if (pCookie)
apr_table_add(r -> pApacheReq->headers_out, "Set-Cookie", pCookie) ;
#if 0
if (r -> Component.Config.bEP1Compat) /* Embperl 2 currently cannot calc Content Length */
set_content_length (r -> pApacheReq, GetContentLength (r) + (r -> Component.pCurrEscape?2:0)) ;
#endif
#ifndef APACHE2
send_http_header (r -> pApacheReq) ;
#endif
for (i = 0; i < hdrs_arr->nelts; ++i)
if (hdrs[i].key)
lprintf (r -> pApp, "[%d]HDR: %s=%s\n", r -> pThread -> nPid, hdrs[i].key, hdrs[i].val) ;
}
}
else
#endif
{
/*char txt[100] ;*/
int save = r -> Component.pOutput -> nMarker ;
SV * pHeader ;
char * p ;
HE * pEntry ;
char * pKey ;
I32 l ;
char * pContentType = "text/html";
STRLEN ldummy ;
/* loc = 0 => no location header found
* loc = 1 => location header found
*/
I32 loc;
r -> Component.pOutput -> nMarker = 0 ; /* output directly */
hv_iterinit (r -> pThread -> pHeaderHash) ;
while ((pEntry = hv_iternext (r -> pThread -> pHeaderHash)))
{
pKey = hv_iterkey (pEntry, &l) ;
pHeader = hv_iterval (r -> pThread -> pHeaderHash, pEntry) ;
loc = 0;
if (pHeader && pKey)
{
if (stricmp (pKey, "location") == 0)
loc = 1;
if (SvROK(pHeader) && SvTYPE(SvRV(pHeader)) == SVt_PVAV )
{
AV * arr = (AV *)SvRV(pHeader);
I32 len = av_len(arr);
int i ;
for (i = 0; i <= len; i++)
{
SV ** svp = av_fetch(arr, i, 0);
p = SvPV(*svp, ldummy);
oputs (r, pKey) ;
oputs (r, ": ") ;
oputs (r, p) ;
oputs (r, "\n") ;
if (r -> Component.Config.bDebug & dbgHeadersIn)
lprintf (r -> pApp, "[%d]HDR: %s: %s\n", r -> pThread -> nPid, pKey, p) ;
if (loc == 1)
break;
}
}
else
{
p = SvPV (pHeader, na) ;
if (stricmp (pKey, "content-type") == 0)
pContentType = p ;
else
{
oputs (r, pKey) ;
oputs (r, ": ") ;
oputs (r, p) ;
oputs (r, "\n") ;
}
if (r -> Component.Config.bDebug & dbgHeadersIn)
lprintf (r -> pApp, "[%d]HDR: %s: %s\n", r -> pThread -> nPid, pKey, p) ;
}
}
}
oputs (r, "Content-Type: ") ;
oputs (r, pContentType) ;
oputs (r, "\n") ;
if (pCookie)
{
oputs (r, "Set-Cookie") ;
oputs (r, ": ") ;
oputs (r, pCookie) ;
oputs (r, "\n") ;
}
oputs (r, "\n") ;
r -> Component.pOutput -> nMarker = save ;
}
return ok ;
}
/* ---------------------------------------------------------------------------- */
/* */
/* End the output stream to memory */
/* */
/* ---------------------------------------------------------------------------- */
static int OutputToMem (/*i/o*/ register req * r)
{
epTHX_
SV * pOut ;
char * pData ;
STRLEN l ;
if (!SvROK (r -> Component.Param.pOutput))
{
strcpy (r -> errdat1, "OutputToMem") ;
strcpy (r -> errdat2, "parameter output") ;
return rcNotScalarRef ;
}
pOut = SvRV (r -> Component.Param.pOutput) ;
if (!r -> bError && r -> Component.pOutputSV && !r -> Component.pImportStash)
{
sv_setsv (pOut, r -> Component.pOutputSV) ;
( run in 0.525 second using v1.01-cache-2.11-cpan-d7f47b0818f )