src/ngx_pagespeed.cc
// Send each buffer in the chain to the proxy_fetch for optimization.
// Eventually it will make it's way, optimized, to base_fetch.
Send each buffer in the chain to the proxy_fetch for optimization.
Eventually it will make it's way, optimized, to base_fetch.
Send each buffer in the chain to the proxy_fetch for optimization . Eventually it will make it ' s way optimized to base_fetch .
void ps_send_to_pagespeed(ngx_http_request_t* r,
                          ps_request_ctx_t* ctx,
                          ps_srv_conf_t* cfg_s,
                          ngx_chain_t* in) {
  ngx_chain_t* cur;
  int last_buf = 0;
  for (cur = in; cur != NULL; cur = cur->next) {
    last_buf = cur->buf->last_buf;
    cur->buf->last_buf = 0;
    CHECK(ctx->proxy_fetch != NULL);
    if (ctx->inflater_ == NULL) {
      ctx->proxy_fetch->Write(
          StringPiece(reinterpret_cast<char*>(cur->buf->pos),
                      cur->buf->last - cur->buf->pos), cfg_s->handler);
    } else {
      char buf[kStackBufferSize];
      ctx->inflater_->SetInput(reinterpret_cast<char*>(cur->buf->pos),
                               cur->buf->last - cur->buf->pos);
      while (ctx->inflater_->HasUnconsumedInput()) {
        int num_inflated_bytes = ctx->inflater_->InflateBytes(
            buf, kStackBufferSize);
        if (num_inflated_bytes < 0) {
          cfg_s->handler->Message(kWarning, "Corrupted inflation");
        } else if (num_inflated_bytes > 0) {
          ctx->proxy_fetch->Write(StringPiece(buf, num_inflated_bytes),
                                  cfg_s->handler);
        }
      }
    }
    if (cur->buf->flush && ctx->follow_flushes) {
      ctx->proxy_fetch->Flush(cfg_s->handler);
    }
    cur->buf->pos = cur->buf->last;
  }
  if (last_buf) {
    ctx->proxy_fetch->Done(true );
    ctx->proxy_fetch = NULL;  
  }
}
void ps_send_to_pagespeed ( ngx_http_request_t * r , ps_request_ctx_t * ctx , ps_srv_conf_t * cfg_s , ngx_chain_t * in ) { ngx_chain_t * cur ; int last_buf = 0 ; for ( cur = in ; cur != NULL ; cur = cur -> next ) { last_buf = cur -> buf -> last_buf ; cur -> buf -> last_buf = 0 ; CHECK ( ctx -> proxy_fetch != NULL ) ; if ( ctx -> inflater_ == NULL ) { ctx -> proxy_fetch -> Write ( StringPiece ( reinterpret_cast < char * > ( cur -> buf -> pos ) , cur -> buf -> last - cur -> buf -> pos ) , cfg_s -> handler ) ; } else { char buf [ kStackBufferSize ] ; ctx -> inflater_ -> SetInput ( reinterpret_cast < char * > ( cur -> buf -> pos ) , cur -> buf -> last - cur -> buf -> pos ) ; while ( ctx -> inflater_ -> HasUnconsumedInput ( ) ) { int num_inflated_bytes = ctx -> inflater_ -> InflateBytes ( buf , kStackBufferSize ) ; if ( num_inflated_bytes < 0 ) { cfg_s -> handler -> Message ( kWarning , " " ) ; } else if ( num_inflated_bytes > 0 ) { ctx -> proxy_fetch -> Write ( StringPiece ( buf , num_inflated_bytes ) , cfg_s -> handler ) ; } } } if ( cur -> buf -> flush && ctx -> follow_flushes ) { ctx -> proxy_fetch -> Flush ( cfg_s -> handler ) ; } cur -> buf -> pos = cur -> buf -> last ; } if ( last_buf ) { ctx -> proxy_fetch -> Done ( true ) ; ctx -> proxy_fetch = NULL ; } }
Send each buffer in the chain to the proxy_fetch for optimization.
Send each buffer in the chain to the proxy_fetch for optimization .
// Buffers are not really the last buffer until they've been through // pagespeed. // Calling ctx->proxy_fetch->Flush(cfg_s->handler) will be a no-op here, // unless we have follow_flushes or flush_html enabled. Note that PSOL // might aggregate multiple flushes into 1, and actually flush a little bit // later due to html parser state and earlier scheduled operations. // Also, unless we also set the flush flag on the nginx buffers we won't // actually flush. // Note that too many flushes could harm optimization over larger html // fragments as PSOL gets less context to work with, e.g. it can't combine // two css files if a flush happens in between. // We're done with buffers as we pass them through, so mark them as sent as // we go. /* success */ // ProxyFetch deletes itself on Done().