/** * Strip HTTP transport implementation details so they don't leak via metadata into * the application layer. */ private static void stripTransportDetails(Metadata metadata) { metadata.discardAll(HTTP2_STATUS); metadata.discardAll(InternalStatus.CODE_KEY); metadata.discardAll(InternalStatus.MESSAGE_KEY); } }
/** * Strip HTTP transport implementation details so they don't leak via metadata into * the application layer. */ private static void stripTransportDetails(Metadata metadata) { metadata.discardAll(HTTP2_STATUS); metadata.discardAll(InternalStatus.CODE_KEY); metadata.discardAll(InternalStatus.MESSAGE_KEY); } }
@Override public PickResult picked(Metadata headers) { headers.discardAll(GrpclbConstants.TOKEN_METADATA_KEY); if (token != null) { headers.put(GrpclbConstants.TOKEN_METADATA_KEY, token); } return result; }
/** * Remove all values for the given key without returning them. This is a minor performance * optimization if you do not need the previous values. * * @throws IllegalStateException if the AmbientContext is frozen */ public <T> void discardAll(Metadata.Key<T> key) { checkFreeze(); contextMetadata.discardAll(key); }
/** * Remove all values for the given key without returning them. This is a minor performance * optimization if you do not need the previous values. * * @throws IllegalStateException if the AmbientContext is frozen */ public <T> void discardAll(Metadata.Key<T> key) { checkFreeze(); contextMetadata.discardAll(key); }
@Override public void setDeadline(Deadline deadline) { headers.discardAll(TIMEOUT_KEY); long effectiveTimeout = max(0, deadline.timeRemaining(TimeUnit.NANOSECONDS)); headers.put(TIMEOUT_KEY, effectiveTimeout); } }
@Override public void setDeadline(Deadline deadline) { headers.discardAll(TIMEOUT_KEY); long effectiveTimeout = max(0, deadline.timeRemaining(TimeUnit.NANOSECONDS)); headers.put(TIMEOUT_KEY, effectiveTimeout); }
@VisibleForTesting static void prepareHeaders( Metadata headers, DecompressorRegistry decompressorRegistry, Compressor compressor, boolean fullStreamDecompression) { headers.discardAll(MESSAGE_ENCODING_KEY); if (compressor != Codec.Identity.NONE) { headers.put(MESSAGE_ENCODING_KEY, compressor.getMessageEncoding()); } headers.discardAll(MESSAGE_ACCEPT_ENCODING_KEY); byte[] advertisedEncodings = InternalDecompressorRegistry.getRawAdvertisedMessageEncodings(decompressorRegistry); if (advertisedEncodings.length != 0) { headers.put(MESSAGE_ACCEPT_ENCODING_KEY, advertisedEncodings); } headers.discardAll(CONTENT_ENCODING_KEY); headers.discardAll(CONTENT_ACCEPT_ENCODING_KEY); if (fullStreamDecompression) { headers.put(CONTENT_ACCEPT_ENCODING_KEY, FULL_STREAM_DECOMPRESSION_ENCODINGS); } }
/** * Based on the deadline, calculate and set the timeout to the given headers. */ private static void updateTimeoutHeaders(@Nullable Deadline effectiveDeadline, @Nullable Deadline callDeadline, @Nullable Deadline outerCallDeadline, Metadata headers) { headers.discardAll(TIMEOUT_KEY); if (effectiveDeadline == null) { return; } long effectiveTimeout = max(0, effectiveDeadline.timeRemaining(TimeUnit.NANOSECONDS)); headers.put(TIMEOUT_KEY, effectiveTimeout); logIfContextNarrowedTimeout(effectiveTimeout, effectiveDeadline, outerCallDeadline, callDeadline); }
private void addStatusToTrailers(Metadata trailers, Status status) { trailers.discardAll(InternalStatus.CODE_KEY); trailers.discardAll(InternalStatus.MESSAGE_KEY); trailers.put(InternalStatus.CODE_KEY, status); if (status.getDescription() != null) { trailers.put(InternalStatus.MESSAGE_KEY, status.getDescription()); } }
private static Metadata toMetadata(com.google.rpc.Status statusProto, Metadata metadata) { checkNotNull(metadata, "metadata must not be null"); metadata.discardAll(STATUS_DETAILS_KEY); metadata.put(STATUS_DETAILS_KEY, statusProto); return metadata; }
@VisibleForTesting static void prepareHeaders( Metadata headers, DecompressorRegistry decompressorRegistry, Compressor compressor, boolean fullStreamDecompression) { headers.discardAll(MESSAGE_ENCODING_KEY); if (compressor != Codec.Identity.NONE) { headers.put(MESSAGE_ENCODING_KEY, compressor.getMessageEncoding()); } headers.discardAll(MESSAGE_ACCEPT_ENCODING_KEY); byte[] advertisedEncodings = InternalDecompressorRegistry.getRawAdvertisedMessageEncodings(decompressorRegistry); if (advertisedEncodings.length != 0) { headers.put(MESSAGE_ACCEPT_ENCODING_KEY, advertisedEncodings); } headers.discardAll(CONTENT_ENCODING_KEY); headers.discardAll(CONTENT_ACCEPT_ENCODING_KEY); if (fullStreamDecompression) { headers.put(CONTENT_ACCEPT_ENCODING_KEY, FULL_STREAM_DECOMPRESSION_ENCODINGS); } }
private void addStatusToTrailers(Metadata trailers, Status status) { trailers.discardAll(InternalStatus.CODE_KEY); trailers.discardAll(InternalStatus.MESSAGE_KEY); trailers.put(InternalStatus.CODE_KEY, status); if (status.getDescription() != null) { trailers.put(InternalStatus.MESSAGE_KEY, status.getDescription()); } }
@Override public ClientStreamTracer newClientStreamTracer(CallOptions callOptions, Metadata headers) { if (span != BlankSpan.INSTANCE) { headers.discardAll(tracingHeader); headers.put(tracingHeader, span.getContext()); } return new ClientTracer(span); }
@Override public ClientStreamTracer newClientStreamTracer(CallOptions callOptions, Metadata headers) { headers.discardAll(tracingHeader); headers.put(tracingHeader, span.getContext()); return new ClientTracer(span); }
@Override public ClientStreamTracer newClientStreamTracer(CallOptions callOptions, Metadata headers) { ClientTracer tracer = new ClientTracer(module, startCtx); // TODO(zhangkun83): Once retry or hedging is implemented, a ClientCall may start more than // one streams. We will need to update this file to support them. if (streamTracerUpdater != null) { checkState( streamTracerUpdater.compareAndSet(this, null, tracer), "Are you creating multiple streams per call? This class doesn't yet support this case"); } else { checkState( streamTracer == null, "Are you creating multiple streams per call? This class doesn't yet support this case"); streamTracer = tracer; } if (module.propagateTags) { headers.discardAll(module.statsHeader); if (!module.tagger.empty().equals(parentCtx)) { headers.put(module.statsHeader, parentCtx); } } return tracer; }
checkState(!closeCalled, "call is closed"); headers.discardAll(MESSAGE_ENCODING_KEY); if (compressor == null) { compressor = Codec.Identity.NONE; headers.discardAll(MESSAGE_ACCEPT_ENCODING_KEY); byte[] advertisedEncodings = InternalDecompressorRegistry.getRawAdvertisedMessageEncodings(decompressorRegistry);
@Override public ClientStreamTracer newClientStreamTracer(CallOptions callOptions, Metadata headers) { ClientTracer tracer = new ClientTracer(); // TODO(zhangkun83): Once retry or hedging is implemented, a ClientCall may start more than // one streams. We will need to update this file to support them. if (streamTracerUpdater != null) { checkState( streamTracerUpdater.compareAndSet(this, null, tracer), "Are you creating multiple streams per call? This class doesn't yet support this case"); } else { checkState( streamTracer == null, "Are you creating multiple streams per call? This class doesn't yet support this case"); streamTracer = tracer; } if (module.propagateTags) { headers.discardAll(module.statsHeader); if (!module.tagger.empty().equals(parentCtx)) { headers.put(module.statsHeader, parentCtx); } } return tracer; }
checkState(!closeCalled, "call is closed"); headers.discardAll(MESSAGE_ENCODING_KEY); if (compressor == null) { compressor = Codec.Identity.NONE; headers.discardAll(MESSAGE_ACCEPT_ENCODING_KEY); byte[] advertisedEncodings = InternalDecompressorRegistry.getRawAdvertisedMessageEncodings(decompressorRegistry);