MCPcopy Create free account
hub / github.com/apache/trafficserver / AuthWriteRedirectedRequest

Function AuthWriteRedirectedRequest

plugins/authproxy/authproxy.cc:355–400  ·  view source on GitHub ↗

Transform the client request into a form that the auth proxy can consume and write it out.

Source from the content-addressed store, hash-verified

353// Transform the client request into a form that the auth proxy can consume and
354// write it out.
355static bool
356AuthWriteRedirectedRequest(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
402static TSEvent
403StateAuthProxyConnect(AuthRequestContext *auth, void * /* edata ATS_UNUSED */)

Callers

nothing calls this directly

Calls 12

TSHttpTxnClientReqGetFunction · 0.85
TSHttpHdrCopyFunction · 0.85
TSHttpHdrUrlGetFunction · 0.85
TSUrlHostSetFunction · 0.85
TSUrlPortSetFunction · 0.85
TSHandleMLocReleaseFunction · 0.85
HttpSetMimeHeaderFunction · 0.85
HttpDebugHeaderFunction · 0.85
TSHttpHdrPrintFunction · 0.85
optionsMethod · 0.80
c_strMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected