mormot对http.sys的封装
mormot对http.sys的封装
windows 2003,xp sp2以上版本开始提供http.sys通讯。
windows为http.sys通讯提供httpapp.dll动态库给外部程序调用。mormot也是调用它。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | procedure HttpApiInitialize; var api: THttpAPIs; P: PPointer; begin if Http.Module<>0 then exit; // already loaded mormot.core.os.GlobalLock; try // if Http.Module<>0 then // by cxg try Http.Module := LoadLibrary(HTTPAPI_DLL); //加载 httpapp.dll Http.Version.MajorVersion := 2; // API 2.0 if all functions are available if Http.Module<=255 then raise EHttpApiServer.CreateFmt( 'Unable to find %s' ,[HTTPAPI_DLL]); P := @@Http.Initialize; for api := low(api) to high(api) do begin P^ := GetProcAddress(Http.Module,HttpNames[api]); if P^=nil then if api<hHttpApi2First then raise EHttpApiServer.CreateFmt( 'Unable to find %s() in %s' ,[HttpNames[api],HTTPAPI_DLL]) else Http.Version.MajorVersion := 1; // e.g. Windows XP or Server 2003 inc(P); end; except on E: Exception do begin if Http.Module>255 then begin FreeLibrary(Http.Module); Http.Module := 0; end; raise; end; end; finally mormot.core.os.GlobalUnlock; end; end; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | /// direct late-binding access to the HTTP API server 1.0 or 2.0 THttpAPI = packed record /// access to the httpapi.dll loaded library Module: THandle; /// will be either 1.0 or 2.0, depending on the published .dll functions Version: HTTP_VERSION; /// The HttpInitialize function initializes the HTTP Server API driver, starts it, // if it has not already been started, and allocates data structures for the // calling application to support response-queue creation and other operations. // Call this function before calling any other functions in the HTTP Server API. Initialize: function(Version: HTTP_VERSION; Flags: cardinal; pReserved: pointer = nil): HRESULT; stdcall; /// The HttpTerminate function cleans up resources used by the HTTP Server API // to process calls by an application. An application should call HttpTerminate // once for every time it called HttpInitialize, with matching flag settings. Terminate: function(Flags: cardinal; Reserved: integer = 0): HRESULT; stdcall; /// The HttpCreateHttpHandle function creates an HTTP request queue for the // calling application and returns a handle to it. CreateHttpHandle: function( var ReqQueueHandle: THandle; Reserved: integer = 0): HRESULT; stdcall; /// The HttpAddUrl function registers a given URL so that requests that match // it are routed to a specified HTTP Server API request queue. An application // can register multiple URLs to a single request queue using repeated calls to // HttpAddUrl // - a typical url prefix is 'http://+:80/vroot/', 'https://+:80/vroot/' or // 'https://adatum.com:443/secure/database/' - here the '+' is called a // Strong wildcard, i.e. will match every IP or server name AddUrl: function(ReqQueueHandle: THandle; UrlPrefix: PWideChar; Reserved: integer = 0): HRESULT; stdcall; /// Unregisters a specified URL, so that requests for it are no longer // routed to a specified queue. RemoveUrl: function(ReqQueueHandle: THandle; UrlPrefix: PWideChar): HRESULT; stdcall; /// retrieves the next available HTTP request from the specified request queue ReceiveHttpRequest: function(ReqQueueHandle: THandle; RequestId: HTTP_REQUEST_ID; Flags: cardinal; var pRequestBuffer: HTTP_REQUEST; RequestBufferLength: ULONG; var pBytesReceived: ULONG; pOverlapped: pointer = nil): HRESULT; stdcall; /// sent the response to a specified HTTP request // - pLogData optional parameter is handled since HTTP API 2.0 SendHttpResponse: function(ReqQueueHandle: THandle; RequestId: HTTP_REQUEST_ID; Flags: integer; var pHttpResponse: HTTP_RESPONSE; pReserved1: pointer; var pBytesSent: cardinal; pReserved2: pointer = nil; Reserved3: ULONG = 0; pOverlapped: pointer = nil; pLogData: PHTTP_LOG_DATA = nil): HRESULT; stdcall; /// receives additional entity body data for a specified HTTP request ReceiveRequestEntityBody: function(ReqQueueHandle: THandle; RequestId: HTTP_REQUEST_ID; Flags: ULONG; pBuffer: pointer; BufferLength: cardinal; var pBytesReceived: cardinal; pOverlapped: pointer = nil): HRESULT; stdcall; /// sends entity-body data associated with an HTTP response. SendResponseEntityBody: function(ReqQueueHandle: THandle; RequestId: HTTP_REQUEST_ID; Flags: integer; EntityChunkCount: word; pEntityChunks: pointer; var pBytesSent: Cardinal; pReserved1: Pointer = nil; pReserved2: Pointer = nil; pOverlapped: POverlapped = nil; pLogData: PHTTP_LOG_DATA = nil): HRESULT; stdcall; /// set specified data, such as IP addresses or SSL Certificates, from the // HTTP Server API configuration store SetServiceConfiguration: function(ServiceHandle: THandle; ConfigId: THttpServiceConfigID; pConfigInformation: pointer; ConfigInformationLength: ULONG; pOverlapped: pointer = nil): HRESULT; stdcall; /// deletes specified data, such as IP addresses or SSL Certificates, from the // HTTP Server API configuration store DeleteServiceConfiguration: function(ServiceHandle: THandle; ConfigId: THttpServiceConfigID; pConfigInformation: pointer; ConfigInformationLength: ULONG; pOverlapped: pointer = nil): HRESULT; stdcall; /// removes from the HTTP Server API cache associated with a given request // queue all response fragments that have a name whose site portion matches // a specified UrlPrefix FlushResponseCache: function(ReqQueueHandle: THandle; pUrlPrefix: PWideChar; Flags: ULONG; pOverlapped: POverlapped): ULONG; stdcall; /// cancels a specified request // - available only for HTTP API 2.0 (since Windows Vista / Server 2008) CancelHttpRequest: function(ReqQueueHandle: THandle; RequestId: HTTP_REQUEST_ID; pOverlapped: pointer = nil): HRESULT; stdcall; /// creates a server session for the specified HTTP API version // - available only for HTTP API 2.0 (since Windows Vista / Server 2008) CreateServerSession: function(Version: HTTP_VERSION; var ServerSessionId: HTTP_SERVER_SESSION_ID; Reserved: ULONG = 0): HRESULT; stdcall; /// deletes the server session identified by the server session ID // - available only for HTTP API 2.0 (since Windows Vista / Server 2008) CloseServerSession: function(ServerSessionId: HTTP_SERVER_SESSION_ID): HRESULT; stdcall; /// creates a new request queue or opens an existing request queue // - available only for HTTP API 2.0 (since Windows Vista / Server 2008) // - replaces the HTTP version 1.0 CreateHttpHandle() function CreateRequestQueue: function(Version: HTTP_VERSION; pName: PWideChar; pSecurityAttributes: Pointer; Flags: ULONG; var ReqQueueHandle: THandle): HRESULT; stdcall; /// sets a new server session property or modifies an existing property // on the specified server session // - available only for HTTP API 2.0 (since Windows Vista / Server 2008) SetServerSessionProperty: function(ServerSessionId: HTTP_SERVER_SESSION_ID; aProperty: HTTP_SERVER_PROPERTY; pPropertyInformation: Pointer; PropertyInformationLength: ULONG): HRESULT; stdcall; /// queries a server property on the specified server session // - available only for HTTP API 2.0 (since Windows Vista / Server 2008) QueryServerSessionProperty: function(ServerSessionId: HTTP_SERVER_SESSION_ID; aProperty: HTTP_SERVER_PROPERTY; pPropertyInformation: Pointer; PropertyInformationLength: ULONG; pReturnLength: PULONG = nil): HRESULT; stdcall; /// creates a URL Group under the specified server session // - available only for HTTP API 2.0 (since Windows Vista / Server 2008) CreateUrlGroup: function(ServerSessionId: HTTP_SERVER_SESSION_ID; var UrlGroupId: HTTP_URL_GROUP_ID; Reserved: ULONG = 0): HRESULT; stdcall; /// closes the URL Group identified by the URL Group ID // - this call also removes all of the URLs that are associated with // the URL Group // - available only for HTTP API 2.0 (since Windows Vista / Server 2008) CloseUrlGroup: function(UrlGroupId: HTTP_URL_GROUP_ID): HRESULT; stdcall; /// adds the specified URL to the URL Group identified by the URL Group ID // - available only for HTTP API 2.0 (since Windows Vista / Server 2008) // - this function replaces the HTTP version 1.0 AddUrl() function AddUrlToUrlGroup: function(UrlGroupId: HTTP_URL_GROUP_ID; pFullyQualifiedUrl: PWideChar; UrlContext: HTTP_URL_CONTEXT = 0; Reserved: ULONG = 0): HRESULT; stdcall; /// removes the specified URL from the group identified by the URL Group ID // - this function removes one, or all, of the URLs from the group // - available only for HTTP API 2.0 (since Windows Vista / Server 2008) // - it replaces the HTTP version 1.0 RemoveUrl() function RemoveUrlFromUrlGroup: function(UrlGroupId: HTTP_URL_GROUP_ID; pFullyQualifiedUrl: PWideChar; Flags: ULONG): HRESULT; stdcall; /// sets a new property or modifies an existing property on the specified // URL Group // - available only for HTTP API 2.0 (since Windows Vista / Server 2008) SetUrlGroupProperty: function(UrlGroupId: HTTP_URL_GROUP_ID; aProperty: HTTP_SERVER_PROPERTY; pPropertyInformation: Pointer; PropertyInformationLength: ULONG): HRESULT; stdcall; /// queries a property on the specified URL Group // - available only for HTTP API 2.0 (since Windows Vista / Server 2008) QueryUrlGroupProperty: function(UrlGroupId: HTTP_URL_GROUP_ID; aProperty: HTTP_SERVER_PROPERTY; pPropertyInformation: Pointer; PropertyInformationLength: ULONG; pReturnLength: PULONG = nil): HRESULT; stdcall; /// sets a new property or modifies an existing property on the request // queue identified by the specified handle // - available only for HTTP API 2.0 (since Windows Vista / Server 2008) SetRequestQueueProperty: function(ReqQueueHandle: THandle; aProperty: HTTP_SERVER_PROPERTY; pPropertyInformation: Pointer; PropertyInformationLength: ULONG; Reserved: ULONG; pReserved: Pointer): HRESULT; stdcall; /// queries a property of the request queue identified by the // specified handle // - available only for HTTP API 2.0 (since Windows Vista / Server 2008) QueryRequestQueueProperty: function(ReqQueueHandle: THandle; aProperty: HTTP_SERVER_PROPERTY; pPropertyInformation: Pointer; PropertyInformationLength: ULONG; Reserved: ULONG; pReturnLength: PULONG; pReserved: Pointer): HRESULT; stdcall; end; |
本文来自博客园,作者:{咏南中间件},转载请注明原文链接:https://www.cnblogs.com/hnxxcxg/p/13473911.html
分类:
mormot
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
2017-08-11 怎样设计REST中间件---中间件JSON对数据库数据的组织
2016-08-11 为方便二层升三层新增的远程方法QuerySql6()
2014-08-11 中间件集群的协议和算法的类语言描述