Example #1
0
void StaticHandler::onRequest(std::unique_ptr<HTTPMessage> headers) noexcept {
  if (headers->getMethod() != HTTPMethod::GET) {
    ResponseBuilder(downstream_)
      .status(400, "Bad method")
      .body("Only GET is supported")
      .sendWithEOM();
    return;
  }
  // a real webserver would validate this path didn't contain malicious
  // characters like '//' or '..'
  try {
    // + 1 to kill leading /
    file_ = std::make_unique<folly::File>(headers->getPath().c_str() + 1);
  } catch (const std::system_error& ex) {
    ResponseBuilder(downstream_)
      .status(404, "Not Found")
      .body(folly::to<std::string>("Could not find ", headers->getPath(),
                                   " ex=", folly::exceptionStr(ex)))
      .sendWithEOM();
    return;
  }
  ResponseBuilder(downstream_)
    .status(200, "Ok")
    .send();
  // use a CPU executor since read(2) of a file can block
  readFileScheduled_ = true;
  folly::getCPUExecutor()->add(
    std::bind(&StaticHandler::readFile, this,
              folly::EventBaseManager::get()->getEventBase()));
}
Example #2
0
void RandomScalerContext::generateMetrics(SkGlyph* glyph) {
    // Here we will change the mask format of the glyph
    // NOTE: this may be overridden by the base class (e.g. if a mask filter is applied).
    switch (glyph->getGlyphID() % 4) {
        case 0: glyph->fMaskFormat = SkMask::kLCD16_Format; break;
        case 1: glyph->fMaskFormat = SkMask::kA8_Format; break;
        case 2: glyph->fMaskFormat = SkMask::kARGB32_Format; break;
        case 3: glyph->fMaskFormat = SkMask::kBW_Format; break;
    }

    fProxy->getMetrics(glyph);

    if (fFakeIt || (glyph->getGlyphID() % 4) != 2) {
        return;
    }

    SkPath path;
    if (!fProxy->getPath(glyph->getPackedID(), &path)) {
        return;
    }
    glyph->fMaskFormat = SkMask::kARGB32_Format;

    SkRect         storage;
    const SkPaint& paint = this->getRandomTypeface()->paint();
    const SkRect&  newBounds =
            paint.doComputeFastBounds(path.getBounds(), &storage, SkPaint::kFill_Style);
    SkIRect ibounds;
    newBounds.roundOut(&ibounds);
    glyph->fLeft   = ibounds.fLeft;
    glyph->fTop    = ibounds.fTop;
    glyph->fWidth  = ibounds.width();
    glyph->fHeight = ibounds.height();
}
Example #3
0
void CopyToDialog::OnOK(wxCommandEvent& event)
{
    //------- parameter validation (BEFORE writing output!) -------
    if (trimCpy(targetFolder->getPath()).empty())
    {
        showNotificationDialog(this, DialogInfoType::INFO, PopupDialogCfg().setMainInstructions(_("Please enter a target folder.")));
        //don't show error icon to follow "Windows' encouraging tone"
        m_targetFolderPath->SetFocus();
        return;
    }
    //-------------------------------------------------------------

    lastUsedPathOut      = targetFolder->getPath();
    keepRelPathsOut      = m_checkBoxKeepRelPath->GetValue();
    overwriteIfExistsOut = m_checkBoxOverwriteIfExists->GetValue();

    folderHistory_->addItem(lastUsedPathOut);

    EndModal(ReturnSmallDlg::BUTTON_OKAY);
}
Example #4
0
void RandomScalerContext::generateImage(const SkGlyph& glyph) {
    // TODO: can force down but not up
    /*
    SkMask::Format format = (SkMask::Format)glyph.fMaskFormat;
    switch (glyph.getGlyphID() % 4) {
        case 0: format = SkMask::kLCD16_Format; break;
        case 1: format = SkMask::kA8_Format; break;
        case 2: format = SkMask::kARGB32_Format; break;
        case 3: format = SkMask::kBW_Format; break;
    }
    const_cast<SkGlyph&>(glyph).fMaskFormat = format;
    */

    if (fFakeIt) {
        sk_bzero(glyph.fImage, glyph.computeImageSize());
        return;
    }

    if (SkMask::kARGB32_Format != glyph.fMaskFormat) {
        fProxy->getImage(glyph);
        return;
    }

    // If the format is ARGB, just draw the glyph from path.
    SkPath path;
    if (!fProxy->getPath(glyph.getPackedID(), &path)) {
        fProxy->getImage(glyph);
        return;
    }

    SkBitmap bm;
    bm.installPixels(SkImageInfo::MakeN32Premul(glyph.fWidth, glyph.fHeight),
                     glyph.fImage,
                     glyph.rowBytes());
    bm.eraseColor(0);

    SkCanvas canvas(bm);
    canvas.translate(-SkIntToScalar(glyph.fLeft), -SkIntToScalar(glyph.fTop));
    canvas.drawPath(path, this->getRandomTypeface()->paint());
}
Example #5
0
void PushRequestHandler::onRequest(
  std::unique_ptr<HTTPMessage> headers) noexcept {
  stats_->recordRequest();
  if (!headers->getHeaders().getSingleOrEmpty("X-PushIt").empty()) {
    downstreamPush_ = downstream_->newPushedResponse(new PushHandler);
    if (!downstreamPush_) {
      // can't push
      return;
    }

    if(headers->getPath() == "/requestLargePush") {
      LOG(INFO) << "sending large push ";

      ResponseBuilder(downstreamPush_)
        .promise("/largePush",
                 headers->getHeaders().getSingleOrEmpty(HTTP_HEADER_HOST))
        .send();

      ResponseBuilder(downstreamPush_)
        .status(200, "OK")
        .body(createLargeBody())
        .sendWithEOM();
    } else {
      LOG(INFO) << "sending small push ";

      ResponseBuilder(downstreamPush_)
        .promise("/pusheen",
                 headers->getHeaders().getSingleOrEmpty(HTTP_HEADER_HOST))
        .send();

      ResponseBuilder(downstreamPush_)
        .status(200, "OK")
        .body(gPushBody)
        .sendWithEOM();
    }
  }
}