Closes the scope after terminating the request.

@param request The request
975255
void afterTerminate(HttpRequest<?> request) {
        Optional<Tracer.SpanInScope> scope = request.removeAttribute(
                TraceRequestAttributes.CURRENT_SCOPE,
                Tracer.SpanInScope.class
        );
        scope.ifPresent(Tracer.SpanInScope::close);
    }
199046
public void init(HttpServletRequest request) {
		resetTimers();
		
		if (request != null) {
			String p = request.getPathInfo();
			final int pathLength = (p == null ? 0 : p.length());
			
			final StringBuffer urlSb = request.getRequestURL();
			String simpleUrl = urlSb.toString(); // without qs
			
			String qs = request.getQueryString();
			if (qs != null) urlSb.append("?").append(qs);
			final String fullUrl = urlSb.toString();
			contextUrl.set(fullUrl);
		
			requestCookies.remove();
			responseCookies.remove();
			
			StringBuilder cookiesDump = new StringBuilder();
			Map<String, Cookie> cookiez = requestCookies.get();
			for (javax.servlet.http.Cookie c : Check.ifNull(request.getCookies(), new javax.servlet.http.Cookie[0])) {
				cookiez.put(c.getName(), new BasicClientCookie(c.getName(), c.getValue()));
				cookiesDump.append(c.toString()).append(";");
			}
	
			String xForwardedFor = request.getHeader(HEADER_X_FORWARDED_FOR);
			clientIp.set(xForwardedFor != null ? xForwardedFor : request.getRemoteAddr());
			
			String xForwardedUrl = request.getHeader(HEADER_X_FORWARDED_URL);
			if (xForwardedUrl != null) {
				int i = xForwardedUrl.lastIndexOf("?");
				simpleUrl = (i == -1 ? xForwardedUrl : xForwardedUrl.substring(0, i));
			}
			
			try {
				simpleUrl = URLDecoder.decode(simpleUrl, "UTF-8"); // convert "%xx" stuff before working with lengths
			} catch (UnsupportedEncodingException e) {
				log.error(e.toString());
			}
			contextPath.set(simpleUrl.substring(0, simpleUrl.length() - pathLength));

			if (verbose) log.info(">>> Time 0 [" + fullUrl + "]. cookies from client: " + cookiesDump.toString());
		}
		
		initialized.set(true);
	}
1135641
@Override
    public void close() {
        synchronized (this.lock) {
            if (this.closed) {
                return;
            }

            this.closed = true;

            // Cancel all pending reads and unregister them.
            ArrayList<Request> toClose = new ArrayList<>(this.pendingRequests.values());
            toClose.forEach(Request::cancel);
        }
    }
313596
private void executeStorageRead(Request request) {
        try {
            byte[] buffer = new byte[request.length];
            getHandle()
                    .thenComposeAsync(handle -> this.storage.read(handle, request.offset, buffer, 0, buffer.length, request.getTimeout()), this.executor)
                    .thenAcceptAsync(bytesRead -> request.complete(new ByteArraySegment(buffer, 0, bytesRead)), this.executor)
                    .whenComplete((r, ex) -> {
                        if (ex != null) {
                            request.fail(ex);
                        }

                        // Unregister the Request after every request fulfillment.
                        finalizeRequest(request);
                    });
        } catch (Throwable ex) {
            if (Exceptions.mustRethrow(ex)) {
                throw ex;
            }

            request.fail(ex);
            finalizeRequest(request);
        }
    }
311572
public void cleanupMultipart(MultipartResourceRequest request) {
        if (request != null) {
            try {
                cleanupFileItems(request.getMultiFileMap());
            } catch (Throwable ex) {
                logger.warn("Failed to perform multipart cleanup for portlet request", ex);
            }
        }
    }
1070421
protected void endRequest() {
        int oldState, newState;
        do {
            oldState = state;
            newState = oldState - 1;
        } while (!stateUpdater.compareAndSet(this, oldState, newState));
        if (newState == CLOSED) {
            handleCompleted();
        }
    }
637134
private void maybeOpenAndSend(final CouchbaseRequest request) {
        LOGGER.debug(logIdent(hostname, PooledService.this)
                + "Need to open a new Endpoint (current size {})", endpoints.size());

        final Endpoint endpoint = endpointFactory.create(
            hostname, bucket, username, password, port, ctx
        );

        synchronized (epMutex) {
            endpoints.add(endpoint);
            endpointStates.register(endpoint, endpoint);
        }

        final Subscription subscription = whenState(endpoint, LifecycleState.CONNECTED,
            new Action1<LifecycleState>() {
                @Override
                public void call(LifecycleState lifecycleState) {
                    if (disconnect) {
                        RetryHelper.retryOrCancel(env, request, responseBuffer);
                    } else {
                        endpoint.send(request);
                        endpoint.send(SignalFlush.INSTANCE);
                    }
                }
            }
        );

        endpoint.connect().subscribe(new Subscriber<LifecycleState>() {
            @Override
            public void onCompleted() {
                // ignored on purpose
            }

            @Override
            public void onError(Throwable e) {
                unsubscribeAndRetry(subscription, request);
            }

            @Override
            public void onNext(LifecycleState state) {
                if (state == LifecycleState.DISCONNECTING || state == LifecycleState.DISCONNECTED) {
                    unsubscribeAndRetry(subscription, request);
                }
            }
        });
    }
8476
public void close(T geoPackage) {
		if (geoPackage != null) {
			try {
				geoPackage.close();
			} catch (Exception e) {
				logger.log(Level.SEVERE, "Error closing GeoPackage: "
						+ geoPackage.getName(), e);
				if (!closeQuietly) {
					throw e;
				}
			}
		}
	}
883137
private void finishRequest()
    throws IOException
  {
    try {
      cleanup();
    } catch (Exception e) {
      log.log(Level.WARNING, e.toString(), e);
    } finally {
      //_requestFacade = null;
    }
  }
295546
public void cancel() {
    if (isOpen()) {
      LOG.debug("Cancelling stream ({})", mDescription);
      mCanceled = true;
      mRequestObserver.cancel("Request is cancelled by user.", null);
    }
  }
1205606
void mergeTo(final NominatimSearchRequest request) {
        if (null == request.getBounded() && null != bounded) {
            request.setBounded(bounded);
        }
        if (null == request.getViewBox()) {
            request.setViewBox(viewBox);
        }
        if (null == request.getPolygonFormat()) {
            request.setPolygonFormat(polygonFormat);
        }
        if (null == request.getAcceptLanguage() && null != acceptLanguage) {
            request.setAcceptLanguage(acceptLanguage.toString());
        }
    }
226355
public CompletableFuture<CloseResponse> close(CloseRequest request) {
    ComposableFuture<CloseResponse> future = new ComposableFuture<>();
    threadContext.execute(() -> {
      PrimaryBackupSession session = sessions.get(request.session());
      if (session != null) {
        role.close(session).whenComplete((result, error) -> {
          if (error == null) {
            future.complete(CloseResponse.ok());
          } else {
            future.complete(CloseResponse.error());
          }
        });
      } else {
        future.complete(CloseResponse.error());
      }
    });
    return future;
  }
96809
public void deleteObject(DeleteObjectRequest request) {
        checkNotNull(request, "request should not be null.");
        assertStringNotNullOrEmpty(request.getKey(), "object key should not be null or empty");

        this.invokeHttpClient(this.createRequest(request, HttpMethodName.DELETE), BosResponse.class);
    }
281099
function (request) {
            var iFrame = request.iFrame;
            if (iFrame) {
                var domEltToRemove = request.iFrameContainer || iFrame;
                domEltToRemove.parentNode.removeChild(domEltToRemove);
                // avoid leaks:
                request.iFrameContainer = null;
                request.iFrame = null;
                iFrame.onload = null;
                iFrame.onreadystatechange = null;
            }
            delete this._requests[request.id];
        }
1156996
@Override
	public void serviceRequest(final Request request) {
		LOG.debug("Before Service Request - Clearing targetable index.");
		UIContext uic = UIContextHolder.getCurrent();

		super.serviceRequest(request);
		// Clear phase scope scratch map
		LOG.debug("After Service Request - Clearing scratch map with phase scope.");
		uic.clearScratchMap();
	}
908088
synchronized void unregisterRequest(HttpRequest request) {
		assertTrue(this == request.requestManager);
		boolean removed = activeRequests.remove(request);
		assertTrue(removed, "Attempted to unregister missing request: %s", request);

		if (removed) {
			notifyRequestFinished(request);
		}
	}
946526
@Override
	public void handleRequest(final Request request) {
		super.handleRequest(request);

		if (isPresent(request)) {
			if (getExpandMode() != ExpandMode.NONE) {
				handleExpansionRequest(request);
			}

			if (getSelectMode() != SelectMode.NONE) {
				handleSelectionRequest(request);
			}

			if (getPaginationMode() != PaginationMode.NONE) {
				handlePaginationRequest(request);
			}

			if (isFilterable()) {
				handleFilterRequest(request);
			}

			if (isSortable()) {
				handleSortRequest(request);
			}
		}
	}