TreeFrog (C + + Web Framework) 가 개발 한 http 파일 서버

2440 단어 framework
개발 자 는 treefrog 를 사용 하여 만 든 프로젝트 입 니 다. 동적 라 이브 러 리 를 만 들 고 tfserver 에 불 러 옵 니 다. tfserver 는 URL 을 contrller, action, argument 세 부분 으로 처리 합 니 다. URL Routing 이 문 서 를 참고 하 십시오.다음 과 같다.
/controller-name/action-name/argument1/argument2/...

우리 의 fileserver 프로젝트 에 대응 하여 controller - name 은 fileserver 이 고 action - name 은 files 이 며 argument 1 은 구체 적 인 파일 이름 입 니 다.파일 에 접근 할 때 다음 주 소 를 사용 합 니 다:http://localhost:8800/fileserver/files/xxx 。
Google 은 이전 Hello World 예제 를 간단하게 개조 하면 http 파일 서버 를 얻 을 수 있 습 니 다.
헤더 파일 은 다음 과 같 습 니 다:
#ifndef FILESERVERCONTROLLER_H
#define FILESERVERCONTROLLER_H
#include "applicationcontroller.h"

class T_CONTROLLER_EXPORT FileServerController : public ApplicationController
{
    Q_OBJECT
public:
    FileServerController(){}
    FileServerController(const FileServerController &other);

public slots:
    void index();
    void files();
    void files(const QString &param);
};

T_DECLARE_CONTROLLER(FileServerController, fileservercontroller);

#endif // FILESERVERCONTROLLER_H

상기 코드 에서 Public slots: 아래 부분 은 action 입 니 다.tfserver 가 URL 을 분석 하면 이 action 으로 호출 됩 니 다.우 리 는 files 라 는 slot 두 개 를 추가 했다.
다음은 원본 파일:
#include "fileservercontroller.h"
FileServerController::FileServerController(const FileServerController &other)
    : ApplicationController()
{}

void FileServerController::index()
{
    renderText("Denied");
}

void FileServerController::files()
{
    renderText("Invalid parameter");
}

void FileServerController::files(const QString &param)
{
    sendFile(param, "application/octet-stream", "");
}

T_REGISTER_CONTROLLER(fileservercontroller);

우 리 는 files 의 실현 에서 단지 sendfile 을 호출 하여 파일 을 보 낼 뿐이다.사실 sendfile 을 추적 하면 이 함 수 는 파일 을 찾 아 열 고 QIODevice 대상 지침 을 THttp Response 의 body Device 구성원 에 게 할당 하 는 것 일 뿐 입 니 다.추 후 에는 TActionThread 에서 이 body Device 로 실제 데이터 전송 동작 을 합 니 다.파일 을 열 때 파 람 은 파일 이름 으로 사이트 루트 디 렉 터 리 에서 찾 습 니 다 (예제 에 서 는 프로젝트 루트 디 렉 터 리).
이제 우 리 는 통과 할 수 있다.http://localhost:8800/fileserver/files/appbase.pri 이 URL 로 다운 로드 를 테스트 해 보 세 요.나 는 이곳 에서 정상적으로 일한다.

좋은 웹페이지 즐겨찾기