hysteria.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233
  1. import { z } from 'zod';
  2. // Hysteria stream transport. Per Xray docs (transports/hysteria.html), the
  3. // Xray implementation of Hysteria2's underlying QUIC transport keeps only
  4. // the essentials — version, auth, udpIdleTimeout, and masquerade. The
  5. // extended bandwidth/window/udphop knobs that earlier hysteria builds
  6. // exposed are not part of this transport's wire shape.
  7. // Inbound masquerade — Xray's hysteria inbound can disguise itself as an
  8. // HTTP/3 server. `type` is the empty string by default (serves the default
  9. // 404 page), and per-type config keys are only honored when their type is
  10. // active.
  11. export const HysteriaMasqueradeSchema = z.object({
  12. type: z.enum(['', 'proxy', 'file', 'string']).default(''),
  13. dir: z.string().default(''),
  14. url: z.string().default(''),
  15. rewriteHost: z.boolean().default(false),
  16. xForwarded: z.boolean().optional(),
  17. insecure: z.boolean().default(false),
  18. content: z.string().default(''),
  19. headers: z.record(z.string(), z.string()).default({}),
  20. statusCode: z.number().int().min(0).default(0),
  21. });
  22. export type HysteriaMasquerade = z.infer<typeof HysteriaMasqueradeSchema>;
  23. export const HysteriaStreamSettingsSchema = z.object({
  24. version: z.literal(2).default(2),
  25. auth: z.string().default(''),
  26. // Xray-core rejects values outside 2-600 seconds at startup.
  27. udpIdleTimeout: z.number().int().min(2).max(600).default(60),
  28. masquerade: HysteriaMasqueradeSchema.optional(),
  29. });
  30. export type HysteriaStreamSettings = z.infer<typeof HysteriaStreamSettingsSchema>;