X-Original-For标头:目的是什么?

时间:2019-09-02 15:22:06

标签: http asp.net-core kestrel-http-server

在记录我的Web应用程序接收的HTTP标头(表现为负载均衡器+ friewall)时,我注意到我收到的X-Original-For和X-Original-Proto标头(除传统的X-Forwared-XXX标头)。

他们的目的是什么?

谢谢。

1 个答案:

答案 0 :(得分:3)

简短答案: let paymentRequest:PKPaymentRequest = PKPaymentRequest() let label = selectedTier == 0 ? "Tier 0 Membership" : "Tier 1 Membership" let amount = selectedTier == 0 ? NSDecimalNumber(value: 99.0) : NSDecimalNumber(value: 189.0) let summary1 = PKPaymentSummaryItem(label: label, amount: amount, type: .final) let total = PKPaymentSummaryItem(label: "total", amount: amount, type: .final) paymentRequest.paymentSummaryItems = [summary1, total] paymentRequest.supportedNetworks = [.visa, .masterCard, .amex, .discover] paymentRequest.merchantCapabilities = [.capability3DS, .capabilityEMV, .capabilityDebit, .capabilityCredit] paymentRequest.currencyCode = "USD" paymentRequest.countryCode = "US" paymentRequest.merchantIdentifier = APPLEPAY_MERCHANTID paymentRequest.applicationData = "ID:123456" .data(using: .utf8) guard let authorizationVC:PKPaymentAuthorizationViewController = PKPaymentAuthorizationViewController(paymentRequest: paymentRequest) else{ return } authorizationVC.delegate = self let delay = DispatchTime.now() + .milliseconds(300) DispatchQueue.main.asyncAfter(deadline: delay) { self.present(authorizationVC, animated: true, completion: nil) } 代表在<{1}和X-Original-*收到的原始标头值

长版:使用HttpContext.Connection / HttpContext.Request / Nginx设置反向代理时,IISApache会更改为左侧, HttpContext.Connnection标头中的大多数值,HttpContext.Request标头用于保存原始的X-Forwarded-*X-Original-*值:

  1. 原始HttpContext.Connection将另存为标题HttpContext.Request,然后将HttpContext.Request.Scheme更改为X-Original-Proto: ...标题中最左侧的方案
  2. 原始HttpContext.Request.Scheme将保存为标题X-Forwarded-Proto: o1, o2, ...,然后HttpContext.Request.Host将更改为X-Original-Host: <original-host>标题中最左侧的主机
  3. 原始HttpContext.Request.HostX-Forwarded-Host: o1, o2, ...将另存为标头HttpContext.Connection.RemoteIpAddress,然后将此值更改为HttpContext.Connection.RemotePort标头中最左边的IP和端口。 / li>

请参见source code of saving X-Original-For

OriginalForHeaderName: <original-endpoint>

请参见source code of saving X-Original-Proto

X-Forwarded-For: o1, o2, ...

请参见source code of saving X-Original-Host

requestHeaders[_options.OriginalForHeaderName] = new IPEndPoint(connection.RemoteIpAddress, connection.RemotePort).ToString();