Transform the client request into a form that the auth proxy can consume and write it out.
| 353 | // Transform the client request into a form that the auth proxy can consume and |
| 354 | // write it out. |
| 355 | static bool |
| 356 | AuthWriteRedirectedRequest(AuthRequestContext *auth) |
| 357 | { |
| 358 | const AuthOptions *options = auth->options(); |
| 359 | HttpHeader rq; |
| 360 | TSMBuffer mbuf; |
| 361 | TSMLoc mhdr; |
| 362 | TSMLoc murl; |
| 363 | char hostbuf[MAX_HOST_LENGTH + 1]; |
| 364 | |
| 365 | TSReleaseAssert(TSHttpTxnClientReqGet(auth->txn, &mbuf, &mhdr) == TS_SUCCESS); |
| 366 | |
| 367 | // First, copy the whole client request to our new auth proxy request. |
| 368 | TSReleaseAssert(TSHttpHdrCopy(rq.buffer, rq.header, mbuf, mhdr) == TS_SUCCESS); |
| 369 | |
| 370 | // Next, we need to rewrite the client request URL so that the request goes to |
| 371 | // the auth proxy instead of the original request. |
| 372 | TSReleaseAssert(TSHttpHdrUrlGet(rq.buffer, rq.header, &murl) == TS_SUCCESS); |
| 373 | |
| 374 | // XXX Possibly we should rewrite the URL to remove the host, port and |
| 375 | // scheme, forcing ATS to go to the Host header. I wonder how HTTPS would |
| 376 | // work in that case. At any rate, we should add a new header containing |
| 377 | // the original host so that the auth proxy can examine it. |
| 378 | TSUrlHostSet(rq.buffer, murl, options->hostname.c_str(), options->hostname.size()); |
| 379 | if (-1 != options->hostport) { |
| 380 | snprintf(hostbuf, sizeof(hostbuf), "%s:%d", options->hostname.c_str(), options->hostport); |
| 381 | TSUrlPortSet(rq.buffer, murl, options->hostport); |
| 382 | } else { |
| 383 | snprintf(hostbuf, sizeof(hostbuf), "%s", options->hostname.c_str()); |
| 384 | } |
| 385 | |
| 386 | TSHandleMLocRelease(rq.buffer, rq.header, murl); |
| 387 | |
| 388 | HttpSetMimeHeader(rq.buffer, rq.header, TS_MIME_FIELD_HOST, hostbuf); |
| 389 | HttpSetMimeHeader(rq.buffer, rq.header, TS_MIME_FIELD_CONTENT_LENGTH, 0u); |
| 390 | HttpSetMimeHeader(rq.buffer, rq.header, TS_MIME_FIELD_CACHE_CONTROL, "no-cache"); |
| 391 | |
| 392 | HttpDebugHeader(rq.buffer, rq.header); |
| 393 | |
| 394 | // Serialize the HTTP request to the write IO buffer. |
| 395 | TSHttpHdrPrint(rq.buffer, rq.header, auth->iobuf.buffer); |
| 396 | |
| 397 | TSHandleMLocRelease(mbuf, TS_NULL_MLOC, mhdr); |
| 398 | TSHandleMLocRelease(rq.buffer, rq.header, murl); |
| 399 | return true; |
| 400 | } |
| 401 | |
| 402 | static TSEvent |
| 403 | StateAuthProxyConnect(AuthRequestContext *auth, void * /* edata ATS_UNUSED */) |
nothing calls this directly
no test coverage detected