Win32 API 日本語リファレンス
ホームNetworking.HttpServer › HttpDeclarePush

HttpDeclarePush

関数
HTTP/2のサーバープッシュ要求を宣言する。
DLLHTTPAPI.dll呼出規約winapi対応OSWindows 10 以降

シグネチャ

// HTTPAPI.dll
#include <windows.h>

DWORD HttpDeclarePush(
    HANDLE RequestQueueHandle,
    ULONGLONG RequestId,
    HTTP_VERB Verb,
    LPCWSTR Path,
    LPCSTR Query,   // optional
    HTTP_REQUEST_HEADERS* Headers   // optional
);

パラメーター

名前方向説明
RequestQueueHandleHANDLEinHttpCreateRequestQueue 関数が返した HTTP.sys リクエストキューへのハンドルです。
RequestIdULONGLONGinプッシュ操作を宣言するリクエストの不透明な識別子です。このリクエストは指定されたキューハンドルからのものである必要があります。
VerbHTTP_VERBinプッシュ操作に使用する HTTP 動詞です。HTTP.sys のプッシュ操作は HttpVerbGETHttpVerbHEAD のみをサポートします。
PathLPCWSTRinプッシュ対象のリソースの URL のパス部分です。
QueryLPCSTRinoptionalプッシュ対象のリソースの URL のクエリ部分です。この文字列の先頭に疑問符 (?) を含めてはなりません。
HeadersHTTP_REQUEST_HEADERS*inoptional

プッシュ操作のリクエストヘッダーです。

HTTP.sys は正しい Host 情報を自動的に生成するため、Host ヘッダーを指定しないでください。HTTP.sys はクロスオリジンのプッシュ操作をサポートしておらず、元のクライアント起点のリクエストと一致する Host 情報を強制し、生成します。

プッシュリクエストはエンティティ本文を持つことができないため、ゼロ以外の Content-Length ヘッダーや Transfer-Encoding ヘッダーを含めることはできません。

戻り値の型: DWORD

公式ドキュメント

HTTP サーバープッシュに使用するリソースとサブリソースの関係を宣言します。基盤となるプロトコル、接続、クライアント、およびポリシーがプッシュ操作を許可する場合、HTTP.sys は指定されたリソースに対して HTTP 2.0 サーバープッシュを実行します。

戻り値

関数が成功した場合は NO_ERROR を返します。

関数が失敗した場合は、WinError.h で定義されている システムエラーコードを返します。

解説(Remarks)

クライアントがサブリソースを自身で検出する原因となる応答バイトを送信する前に、HttpDeclarePush を呼び出す必要があります。この順序を守らないと、リソースをプッシュするサーバーとリソースを取得するクライアントの間で競合が発生し、帯域幅を浪費する可能性があります。 サーバーアプリケーションは、必要であることが高い確度で見込まれ、かつクライアントによってまだキャッシュされていないリソースをプッシュする場合にのみ HttpDeclarePush を使用してください。サーバーアプリケーションがそれ以外のリソースをプッシュすると、帯域幅と CPU が不必要に消費される可能性があります。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// HTTPAPI.dll
#include <windows.h>

DWORD HttpDeclarePush(
    HANDLE RequestQueueHandle,
    ULONGLONG RequestId,
    HTTP_VERB Verb,
    LPCWSTR Path,
    LPCSTR Query,   // optional
    HTTP_REQUEST_HEADERS* Headers   // optional
);
[DllImport("HTTPAPI.dll", ExactSpelling = true)]
static extern uint HttpDeclarePush(
    IntPtr RequestQueueHandle,   // HANDLE
    ulong RequestId,   // ULONGLONG
    int Verb,   // HTTP_VERB
    [MarshalAs(UnmanagedType.LPWStr)] string Path,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPStr)] string Query,   // LPCSTR optional
    IntPtr Headers   // HTTP_REQUEST_HEADERS* optional
);
<DllImport("HTTPAPI.dll", ExactSpelling:=True)>
Public Shared Function HttpDeclarePush(
    RequestQueueHandle As IntPtr,   ' HANDLE
    RequestId As ULong,   ' ULONGLONG
    Verb As Integer,   ' HTTP_VERB
    <MarshalAs(UnmanagedType.LPWStr)> Path As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPStr)> Query As String,   ' LPCSTR optional
    Headers As IntPtr   ' HTTP_REQUEST_HEADERS* optional
) As UInteger
End Function
' RequestQueueHandle : HANDLE
' RequestId : ULONGLONG
' Verb : HTTP_VERB
' Path : LPCWSTR
' Query : LPCSTR optional
' Headers : HTTP_REQUEST_HEADERS* optional
Declare PtrSafe Function HttpDeclarePush Lib "httpapi" ( _
    ByVal RequestQueueHandle As LongPtr, _
    ByVal RequestId As LongLong, _
    ByVal Verb As Long, _
    ByVal Path As LongPtr, _
    ByVal Query As String, _
    ByVal Headers As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

HttpDeclarePush = ctypes.windll.httpapi.HttpDeclarePush
HttpDeclarePush.restype = wintypes.DWORD
HttpDeclarePush.argtypes = [
    wintypes.HANDLE,  # RequestQueueHandle : HANDLE
    ctypes.c_ulonglong,  # RequestId : ULONGLONG
    ctypes.c_int,  # Verb : HTTP_VERB
    wintypes.LPCWSTR,  # Path : LPCWSTR
    wintypes.LPCSTR,  # Query : LPCSTR optional
    ctypes.c_void_p,  # Headers : HTTP_REQUEST_HEADERS* optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('HTTPAPI.dll')
HttpDeclarePush = Fiddle::Function.new(
  lib['HttpDeclarePush'],
  [
    Fiddle::TYPE_VOIDP,  # RequestQueueHandle : HANDLE
    -Fiddle::TYPE_LONG_LONG,  # RequestId : ULONGLONG
    Fiddle::TYPE_INT,  # Verb : HTTP_VERB
    Fiddle::TYPE_VOIDP,  # Path : LPCWSTR
    Fiddle::TYPE_VOIDP,  # Query : LPCSTR optional
    Fiddle::TYPE_VOIDP,  # Headers : HTTP_REQUEST_HEADERS* optional
  ],
  -Fiddle::TYPE_INT)
#[link(name = "httpapi")]
extern "system" {
    fn HttpDeclarePush(
        RequestQueueHandle: *mut core::ffi::c_void,  // HANDLE
        RequestId: u64,  // ULONGLONG
        Verb: i32,  // HTTP_VERB
        Path: *const u16,  // LPCWSTR
        Query: *const u8,  // LPCSTR optional
        Headers: *mut HTTP_REQUEST_HEADERS  // HTTP_REQUEST_HEADERS* optional
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("HTTPAPI.dll")]
public static extern uint HttpDeclarePush(IntPtr RequestQueueHandle, ulong RequestId, int Verb, [MarshalAs(UnmanagedType.LPWStr)] string Path, [MarshalAs(UnmanagedType.LPStr)] string Query, IntPtr Headers);
"@
$api = Add-Type -MemberDefinition $sig -Name 'HTTPAPI_HttpDeclarePush' -Namespace Win32 -PassThru
# $api::HttpDeclarePush(RequestQueueHandle, RequestId, Verb, Path, Query, Headers)
#uselib "HTTPAPI.dll"
#func global HttpDeclarePush "HttpDeclarePush" sptr, sptr, sptr, sptr, sptr, sptr
; HttpDeclarePush RequestQueueHandle, RequestId, Verb, Path, Query, varptr(Headers)   ; 戻り値は stat
; RequestQueueHandle : HANDLE -> "sptr"
; RequestId : ULONGLONG -> "sptr"
; Verb : HTTP_VERB -> "sptr"
; Path : LPCWSTR -> "sptr"
; Query : LPCSTR optional -> "sptr"
; Headers : HTTP_REQUEST_HEADERS* optional -> "sptr"
; ※HSP3.7は int64 引数(64bit値渡し)に非対応です。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "HTTPAPI.dll"
#cfunc global HttpDeclarePush "HttpDeclarePush" sptr, int64, int, wstr, str, var
; res = HttpDeclarePush(RequestQueueHandle, RequestId, Verb, Path, Query, Headers)
; RequestQueueHandle : HANDLE -> "sptr"
; RequestId : ULONGLONG -> "int64"
; Verb : HTTP_VERB -> "int"
; Path : LPCWSTR -> "wstr"
; Query : LPCSTR optional -> "str"
; Headers : HTTP_REQUEST_HEADERS* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
; ※int64 引数の DLL 値渡しは x64 ランタイム(hsp3_64)のみ対応(x86 は未対応)。
出力引数:
; DWORD HttpDeclarePush(HANDLE RequestQueueHandle, ULONGLONG RequestId, HTTP_VERB Verb, LPCWSTR Path, LPCSTR Query, HTTP_REQUEST_HEADERS* Headers)
#uselib "HTTPAPI.dll"
#cfunc global HttpDeclarePush "HttpDeclarePush" intptr, int64, int, wstr, str, var
; res = HttpDeclarePush(RequestQueueHandle, RequestId, Verb, Path, Query, Headers)
; RequestQueueHandle : HANDLE -> "intptr"
; RequestId : ULONGLONG -> "int64"
; Verb : HTTP_VERB -> "int"
; Path : LPCWSTR -> "wstr"
; Query : LPCSTR optional -> "str"
; Headers : HTTP_REQUEST_HEADERS* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	httpapi = windows.NewLazySystemDLL("HTTPAPI.dll")
	procHttpDeclarePush = httpapi.NewProc("HttpDeclarePush")
)

// RequestQueueHandle (HANDLE), RequestId (ULONGLONG), Verb (HTTP_VERB), Path (LPCWSTR), Query (LPCSTR optional), Headers (HTTP_REQUEST_HEADERS* optional)
r1, _, err := procHttpDeclarePush.Call(
	uintptr(RequestQueueHandle),
	uintptr(RequestId),
	uintptr(Verb),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(Path))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(Query))),
	uintptr(Headers),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function HttpDeclarePush(
  RequestQueueHandle: THandle;   // HANDLE
  RequestId: UInt64;   // ULONGLONG
  Verb: Integer;   // HTTP_VERB
  Path: PWideChar;   // LPCWSTR
  Query: PAnsiChar;   // LPCSTR optional
  Headers: Pointer   // HTTP_REQUEST_HEADERS* optional
): DWORD; stdcall;
  external 'HTTPAPI.dll' name 'HttpDeclarePush';
result := DllCall("HTTPAPI\HttpDeclarePush"
    , "Ptr", RequestQueueHandle   ; HANDLE
    , "Int64", RequestId   ; ULONGLONG
    , "Int", Verb   ; HTTP_VERB
    , "WStr", Path   ; LPCWSTR
    , "AStr", Query   ; LPCSTR optional
    , "Ptr", Headers   ; HTTP_REQUEST_HEADERS* optional
    , "UInt")   ; return: DWORD
●HttpDeclarePush(RequestQueueHandle, RequestId, Verb, Path, Query, Headers) = DLL("HTTPAPI.dll", "dword HttpDeclarePush(void*, qword, int, char*, char*, void*)")
# 呼び出し: HttpDeclarePush(RequestQueueHandle, RequestId, Verb, Path, Query, Headers)
# RequestQueueHandle : HANDLE -> "void*"
# RequestId : ULONGLONG -> "qword"
# Verb : HTTP_VERB -> "int"
# Path : LPCWSTR -> "char*"
# Query : LPCSTR optional -> "char*"
# Headers : HTTP_REQUEST_HEADERS* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "httpapi" fn HttpDeclarePush(
    RequestQueueHandle: ?*anyopaque, // HANDLE
    RequestId: u64, // ULONGLONG
    Verb: i32, // HTTP_VERB
    Path: [*c]const u16, // LPCWSTR
    Query: [*c]const u8, // LPCSTR optional
    Headers: [*c]HTTP_REQUEST_HEADERS // HTTP_REQUEST_HEADERS* optional
) callconv(std.os.windows.WINAPI) u32;
proc HttpDeclarePush(
    RequestQueueHandle: pointer,  # HANDLE
    RequestId: uint64,  # ULONGLONG
    Verb: int32,  # HTTP_VERB
    Path: WideCString,  # LPCWSTR
    Query: cstring,  # LPCSTR optional
    Headers: ptr HTTP_REQUEST_HEADERS  # HTTP_REQUEST_HEADERS* optional
): uint32 {.importc: "HttpDeclarePush", stdcall, dynlib: "HTTPAPI.dll".}
pragma(lib, "httpapi");
extern(Windows)
uint HttpDeclarePush(
    void* RequestQueueHandle,   // HANDLE
    ulong RequestId,   // ULONGLONG
    int Verb,   // HTTP_VERB
    const(wchar)* Path,   // LPCWSTR
    const(char)* Query,   // LPCSTR optional
    HTTP_REQUEST_HEADERS* Headers   // HTTP_REQUEST_HEADERS* optional
);
ccall((:HttpDeclarePush, "HTTPAPI.dll"), stdcall, UInt32,
      (Ptr{Cvoid}, UInt64, Int32, Cwstring, Cstring, Ptr{HTTP_REQUEST_HEADERS}),
      RequestQueueHandle, RequestId, Verb, Path, Query, Headers)
# RequestQueueHandle : HANDLE -> Ptr{Cvoid}
# RequestId : ULONGLONG -> UInt64
# Verb : HTTP_VERB -> Int32
# Path : LPCWSTR -> Cwstring
# Query : LPCSTR optional -> Cstring
# Headers : HTTP_REQUEST_HEADERS* optional -> Ptr{HTTP_REQUEST_HEADERS}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t HttpDeclarePush(
    void* RequestQueueHandle,
    uint64_t RequestId,
    int32_t Verb,
    const uint16_t* Path,
    const char* Query,
    void* Headers);
]]
local httpapi = ffi.load("httpapi")
-- httpapi.HttpDeclarePush(RequestQueueHandle, RequestId, Verb, Path, Query, Headers)
-- RequestQueueHandle : HANDLE
-- RequestId : ULONGLONG
-- Verb : HTTP_VERB
-- Path : LPCWSTR
-- Query : LPCSTR optional
-- Headers : HTTP_REQUEST_HEADERS* optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('HTTPAPI.dll');
const HttpDeclarePush = lib.func('__stdcall', 'HttpDeclarePush', 'uint32_t', ['void *', 'uint64_t', 'int32_t', 'str16', 'str', 'void *']);
// HttpDeclarePush(RequestQueueHandle, RequestId, Verb, Path, Query, Headers)
// RequestQueueHandle : HANDLE -> 'void *'
// RequestId : ULONGLONG -> 'uint64_t'
// Verb : HTTP_VERB -> 'int32_t'
// Path : LPCWSTR -> 'str16'
// Query : LPCSTR optional -> 'str'
// Headers : HTTP_REQUEST_HEADERS* optional -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("HTTPAPI.dll", {
  HttpDeclarePush: { parameters: ["pointer", "u64", "i32", "buffer", "buffer", "pointer"], result: "u32" },
});
// lib.symbols.HttpDeclarePush(RequestQueueHandle, RequestId, Verb, Path, Query, Headers)
// RequestQueueHandle : HANDLE -> "pointer"
// RequestId : ULONGLONG -> "u64"
// Verb : HTTP_VERB -> "i32"
// Path : LPCWSTR -> "buffer"
// Query : LPCSTR optional -> "buffer"
// Headers : HTTP_REQUEST_HEADERS* optional -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t HttpDeclarePush(
    void* RequestQueueHandle,
    uint64_t RequestId,
    int32_t Verb,
    const uint16_t* Path,
    const char* Query,
    void* Headers);
C, "HTTPAPI.dll");
// $ffi->HttpDeclarePush(RequestQueueHandle, RequestId, Verb, Path, Query, Headers);
// RequestQueueHandle : HANDLE
// RequestId : ULONGLONG
// Verb : HTTP_VERB
// Path : LPCWSTR
// Query : LPCSTR optional
// Headers : HTTP_REQUEST_HEADERS* optional
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Httpapi extends StdCallLibrary {
    Httpapi INSTANCE = Native.load("httpapi", Httpapi.class);
    int HttpDeclarePush(
        Pointer RequestQueueHandle,   // HANDLE
        long RequestId,   // ULONGLONG
        int Verb,   // HTTP_VERB
        WString Path,   // LPCWSTR
        String Query,   // LPCSTR optional
        Pointer Headers   // HTTP_REQUEST_HEADERS* optional
    );
}
@[Link("httpapi")]
lib LibHTTPAPI
  fun HttpDeclarePush = HttpDeclarePush(
    RequestQueueHandle : Void*,   # HANDLE
    RequestId : UInt64,   # ULONGLONG
    Verb : Int32,   # HTTP_VERB
    Path : UInt16*,   # LPCWSTR
    Query : UInt8*,   # LPCSTR optional
    Headers : HTTP_REQUEST_HEADERS*   # HTTP_REQUEST_HEADERS* optional
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef HttpDeclarePushNative = Uint32 Function(Pointer<Void>, Uint64, Int32, Pointer<Utf16>, Pointer<Utf8>, Pointer<Void>);
typedef HttpDeclarePushDart = int Function(Pointer<Void>, int, int, Pointer<Utf16>, Pointer<Utf8>, Pointer<Void>);
final HttpDeclarePush = DynamicLibrary.open('HTTPAPI.dll')
    .lookupFunction<HttpDeclarePushNative, HttpDeclarePushDart>('HttpDeclarePush');
// RequestQueueHandle : HANDLE -> Pointer<Void>
// RequestId : ULONGLONG -> Uint64
// Verb : HTTP_VERB -> Int32
// Path : LPCWSTR -> Pointer<Utf16>
// Query : LPCSTR optional -> Pointer<Utf8>
// Headers : HTTP_REQUEST_HEADERS* optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function HttpDeclarePush(
  RequestQueueHandle: THandle;   // HANDLE
  RequestId: UInt64;   // ULONGLONG
  Verb: Integer;   // HTTP_VERB
  Path: PWideChar;   // LPCWSTR
  Query: PAnsiChar;   // LPCSTR optional
  Headers: Pointer   // HTTP_REQUEST_HEADERS* optional
): DWORD; stdcall;
  external 'HTTPAPI.dll' name 'HttpDeclarePush';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "HttpDeclarePush"
  c_HttpDeclarePush :: Ptr () -> Word64 -> Int32 -> CWString -> CString -> Ptr () -> IO Word32
-- RequestQueueHandle : HANDLE -> Ptr ()
-- RequestId : ULONGLONG -> Word64
-- Verb : HTTP_VERB -> Int32
-- Path : LPCWSTR -> CWString
-- Query : LPCSTR optional -> CString
-- Headers : HTTP_REQUEST_HEADERS* optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let httpdeclarepush =
  foreign "HttpDeclarePush"
    ((ptr void) @-> uint64_t @-> int32_t @-> (ptr uint16_t) @-> string @-> (ptr void) @-> returning uint32_t)
(* RequestQueueHandle : HANDLE -> (ptr void) *)
(* RequestId : ULONGLONG -> uint64_t *)
(* Verb : HTTP_VERB -> int32_t *)
(* Path : LPCWSTR -> (ptr uint16_t) *)
(* Query : LPCSTR optional -> string *)
(* Headers : HTTP_REQUEST_HEADERS* optional -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library httpapi (t "HTTPAPI.dll"))
(cffi:use-foreign-library httpapi)

(cffi:defcfun ("HttpDeclarePush" http-declare-push :convention :stdcall) :uint32
  (request-queue-handle :pointer)   ; HANDLE
  (request-id :uint64)   ; ULONGLONG
  (verb :int32)   ; HTTP_VERB
  (path (:string :encoding :utf-16le))   ; LPCWSTR
  (query :string)   ; LPCSTR optional
  (headers :pointer))   ; HTTP_REQUEST_HEADERS* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $HttpDeclarePush = Win32::API::More->new('HTTPAPI',
    'DWORD HttpDeclarePush(HANDLE RequestQueueHandle, UINT64 RequestId, int Verb, LPCWSTR Path, LPCSTR Query, LPVOID Headers)');
# my $ret = $HttpDeclarePush->Call($RequestQueueHandle, $RequestId, $Verb, $Path, $Query, $Headers);
# RequestQueueHandle : HANDLE -> HANDLE
# RequestId : ULONGLONG -> UINT64
# Verb : HTTP_VERB -> int
# Path : LPCWSTR -> LPCWSTR
# Query : LPCSTR optional -> LPCSTR
# Headers : HTTP_REQUEST_HEADERS* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目
使用する型