public static void publishArrayResponse(int requestContext, int sequence, int status, Pipe<ServerResponseSchema> localOutput, long channelId, byte[] typeBytes, int contentLength, byte[] contentBacking, int contentPosition, int contentMask) { int channelIdHigh = (int)(channelId>>32); int channelIdLow = (int)channelId; publishArrayResponse(requestContext, sequence, status, localOutput, channelIdHigh, channelIdLow, typeBytes, contentLength, contentBacking, contentPosition, contentMask); }
@Override public void timeout(Pipe<ServerResponseSchema> output) { HTTPUtil.publishStatus(channelId, sequence, 404, output); }
public static TrieParser buildHeaderParser(StructRegistry schema, int structId, HTTPHeader ... headers) { boolean skipDeepChecks = false; //TODO: does not make as big a difference as expected. boolean supportsExtraction = true; boolean ignoreCase = true; TrieParser headerParser = new TrieParser(256,4,skipDeepChecks,supportsExtraction,ignoreCase); addHeader(headerParser,HTTPSpecification.END_OF_HEADER_ID, ""); int i = headers.length; while (--i>=0) { addHeader(schema, structId, headerParser, headers[i]); } addHeader(headerParser, HTTPSpecification.UNKNOWN_HEADER_ID, "%b: %b"); return headerParser; }
private static void writeHeader(NetResponseWriter outputStream, final int headerBlobPosition, final long positionOfLen, int statusCode, final int context, HTTPContentType contentType, int length, boolean chunked) { //logger.info("writing head at position {} ", headerBlobPosition); DataOutputBlobWriter.openFieldAtPosition(outputStream, headerBlobPosition); byte[] revisionBytes = HTTPRevisionDefaults.HTTP_1_1.getBytes(); byte[] etagBytes = null;//TODO: nice feature to add later int connectionIsClosed = 1&(context>>ServerCoordinator.CLOSE_CONNECTION_SHIFT); byte[] typeBytes = null!=contentType?contentType.getBytes():null; HTTPUtil.writeHeader(revisionBytes, statusCode, 0, etagBytes, typeBytes, length, chunked, true, outputStream, connectionIsClosed, w -> w.write(HTTPHeaderDefaults.DATE, outputStream.headerDate) ); int propperLength = DataOutputBlobWriter.length(outputStream); Pipe.validateVarLength(outputStream.getPipe(), propperLength); Pipe.setIntValue(propperLength, outputStream.getPipe(), positionOfLen); //go back and set the right length. outputStream.getPipe().closeBlobFieldWrite(); }
int channelIdLow = (int)activeConnectionId; HTTPUtil.publishArrayResponse(ServerCoordinator.END_RESPONSE_MASK | ServerCoordinator.CLOSE_CONNECTION_MASK, activeSequenceId, statusId, output, channelIdHigh, channelIdLow, null, contentLength, contentBacking, contentPosition, contentMask); HTTPUtil.publishStatus(activeConnectionId, activeSequenceId, 200, output);
this.structId = HTTPUtil.newHTTPStruct(scs.registry); if (null != this.extractor) { this.extractor.addToStruct(scs.registry, structId); HTTPUtil.addHeader(headerParser,HTTPSpecification.END_OF_HEADER_ID,""); HTTPUtil.addHeader(scs.registry, structId, headerParser, header); HTTPUtil.addHeader(scs.registry, structId, headerParser, HTTPHeaderDefaults.CONTENT_LENGTH); HTTPUtil.addHeader(scs.registry, structId, headerParser, HTTPHeaderDefaults.TRANSFER_ENCODING); HTTPUtil.addHeader(scs.registry, structId, headerParser, HTTPHeaderDefaults.CONNECTION); HTTPUtil.addHeader(scs.registry, structId, headerParser, HTTPHeaderDefaults.HOST); HTTPUtil.addHeader(scs.registry, structId, headerParser, HTTPHeaderDefaults.CONTENT_TYPE); HTTPUtil.addHeader(scs.registry, structId, headerParser, HTTPHeaderDefaults.ACCEPT_LANGUAGE); HTTPUtil.addHeader(scs.registry, structId, headerParser, HTTPHeaderDefaults.ACCEPT_ENCODING); HTTPUtil.addHeader(scs.registry, structId, headerParser, HTTPHeaderDefaults.REFERER); HTTPUtil.addHeader(scs.registry, structId, headerParser, HTTPHeaderDefaults.ORIGIN); HTTPUtil.addHeader(scs.registry, structId, headerParser, HTTPHeaderDefaults.DNT); HTTPUtil.addHeader(scs.registry, structId, headerParser, HTTPHeaderDefaults.USER_AGENT);
int pathId = UNMAPPED_ROUTE; int structId = HTTPUtil.newHTTPStruct(conStruct.registry); unmappedPathField = conStruct.registry.growStruct(structId,StructType.Text,0,"path".getBytes()); conStruct.registry.setAssociatedObject(unmappedPathField, "path"); UNMAPPED_STRUCT = structId; unmappedHeaders = HTTPUtil.buildHeaderParser( conStruct.registry, structId,
public static int structureId(int sessionId, StructRegistry typeData) { assert(sessionId!=0) : "sessionId may not be zero"; assert(sessionId>0) : "sessionId must be positive"; int result = typeData.lookupAlias(sessionId); if (result!=0) { return result; } else { //was zero so find if its missing if (typeData.isValidAlias(sessionId)) { return result; //this zero is valid } } //need to add new item int newStructId = HTTPUtil.newHTTPStruct(typeData); return typeData.storeAlias(sessionId, newStructId); }
public static void closePayloadAndPublish( HTTPUtilResponse that, byte[] eTag, HTTPContentType contentTypeEnum, Pipe<ServerResponseSchema> output, long activeChannelId, int activeSequenceNo, int activeFieldRequestContext, ChannelWriter outputStream, HeaderWritable additionalHeaderWriter, int status) { storeChnlAndSeqInHeaderFragment(that, output, activeChannelId, activeSequenceNo); byte[] contentType = null!=contentTypeEnum ? contentTypeEnum.getBytes() : null; int totalLengthWritten = outputStream.length(); //this is a key pronghorn pattern in use here output.closeBlobFieldWrite(); //closed because we will add each part below... HTTPUtil.prependBodyWithHeader(output, eTag, totalLengthWritten, that, activeFieldRequestContext, activeChannelId, activeSequenceNo, contentType, additionalHeaderWriter, status);//context }
headerParsers[sessionId] = HTTPUtil.buildHeaderParser( recordTypeData, structureId,
boolean server = false; byte[] eTagBytes = null; HTTPUtil.writeHeader( HTTPRevisionDefaults.HTTP_1_1.getBytes(), status, requestContext, eTagBytes, typeBytes,
public static void publishStatus(long channelId, int sequence, int status, Pipe<ServerResponseSchema> localOutput) { int channelIdHigh = (int)(channelId>>32); int channelIdLow = (int)channelId; publishStatus(sequence, status, channelIdHigh, channelIdLow, localOutput); }
public static void publishStatus(int sequence, int status, int channelIdHigh, int channelIdLow, Pipe<ServerResponseSchema> localOutput) { int contentLength = 0; byte[] contentBacking = null; int contentPosition = 0; int contentMask = Integer.MAX_VALUE; publishArrayResponse(ServerCoordinator.END_RESPONSE_MASK, sequence, status, localOutput, channelIdHigh, channelIdLow, null, contentLength, contentBacking, contentPosition, contentMask); }
HTTPUtilResponse.openToEmptyBlock(ebh, localOut); writeHeader(
public static void addHeader(StructRegistry schema, int structId, TrieParser headerParser, HTTPHeader header) { long fieldId = schema.growStruct(structId, StructType.Blob, //TODO: need a way to define dimensions on headers 0, //NOTE: associated object will be used to interpret header.rootBytes()); if (!schema.setAssociatedObject(fieldId, header)) { throw new UnsupportedOperationException("A header with the same identity hash is already held, can not add "+header); } assert(schema.getAssociatedObject(fieldId) == header) : "unable to get associated object"; assert(fieldId == schema.fieldLookupByIdentity(header, structId)); CharSequence template = header.readingTemplate(); addHeader(headerParser, fieldId, template); }
private void publishErrorHeader(int httpRevision, int requestContext, int sequence, Exception e, Pipe<HTTPRequestSchema> input, Pipe<ServerResponseSchema> output) { if (null != e) { logger.error("Unable to read file for sending.",e); } //Informational 1XX, Successful 2XX, Redirection 3XX, Client Error 4XX and Server Error 5XX. int errorStatus = null==e? 400:500; HTTPUtil.publishStatus(sequence, errorStatus, activeChannelHigh, activeChannelLow, output); Pipe.confirmLowLevelRead(input, activeReadMessageSize); Pipe.releaseReadLock(input); }
public static void publishArrayResponse(int requestContext, int sequence, int status, Pipe<ServerResponseSchema> localOutput, long channelId, byte[] typeBytes, byte[] content) { int channelIdHigh = (int)(channelId>>32); int channelIdLow = (int)channelId; publishArrayResponse(requestContext, sequence, status, localOutput, channelIdHigh, channelIdLow, typeBytes, content); }
boolean server = false; byte[] eTagBytes = null; HTTPUtil.writeHeader( HTTPRevisionDefaults.HTTP_1_1.getBytes(), status, requestContext, eTagBytes, typeBytes,
private boolean sendError(final long channel, final int idx, int errorCode) { boolean sent = false; if (Pipe.hasRoomForWrite(errorResponsePipe)) { //will close connection as soon as error is returned. HTTPUtil.publishStatus(channel, sequences[idx], errorCode, errorResponsePipe); sequences[idx]++; sent = true; } sendRelease(channel, idx); return sent; }
private void processRequest(int httpRequestResponseId, Pipe<ServerResponseSchema> output, Pipe<ClientHTTPRequestSchema> toTwitter, long friendUserId, long connectionId, int sequenceID) { long now = System.currentTimeMillis(); if (isThisTheTime(now)) { //do it now, toTwitter then take response and relay it back publishRequest(toTwitter, httpRequestResponseId, friendUserId); } else { //too quickly, send back 420 int contentLength = 1; long seconds = ( (nextTriggerTime-now)+1000 )/1000; if (seconds>127) { //cap out at 127 seconds seconds = 127; } contentBacking[0] = (byte)seconds; int channelIdHigh = (int)(connectionId>>32); int channelIdLow = (int)connectionId; HTTPUtil.publishArrayResponse(ServerCoordinator.END_RESPONSE_MASK | ServerCoordinator.CLOSE_CONNECTION_MASK, sequenceID, 420, output, channelIdHigh, channelIdLow, null, contentLength, contentBacking, contentPosition, contentMask); //clear so the next call will not be blocked activeConnectionId = -1; activeSequenceId = -1; } }