How to release request_body->buffs after I read them - nginx

I write a Nginx module, the client will post stream data to it. But I found the client will be blocked after send about 64KB data(http body's size). I try to change the Nginx config client_body_buffer_size, after that the client can send more data.
r->request_body_no_buffering = 1; ngx_http_read_client_request_body(r, body_handler);
Do I have to do something in the body_handler function which release the request_body->buffs?
I try to use ngx_free_chain, but it doesn't work.

Related

How does a VLC client ask the server for more data in application layer (HTTP)?

I am working on a project related to video streaming. I have been reading the http code extensively in the access_output and access modules. My question is regarding how the client asks the server to send more data in the application layer, specifically using http. I assume it is within the httpd file located in the src/network folder, but I have been writing to log files and I can't seem to figure out how the client asks for the data. It really seems like the server just sends it to the client without acknowledgement, but I highly doubt this is the case.
Thank you so much for your help!
Requesting more data is achieved using HTTP GET with a Range header.
Examples:
Range: bytes=123-
Range: bytes=123-456
In VLC you can find the relevant code in modules/access/http.c:
static int Request( access_t *p_access, uint64_t i_tell )
{
[...]
/* Offset */
if( p_sys->i_version == 1 && ! p_sys->b_continuous )
{
p_sys->b_persist = true;
net_Printf( p_access, p_sys->fd, pvs,
"Range: bytes=%"PRIu64"-\r\n", i_tell );
net_Printf( p_access, p_sys->fd, pvs, "Connection: close\r\n" );
}
See also: HTTP Range Requests in the RFC.

Netty - sending http requests over ssl

I'm trying to get a client/server program exchanging http messages over ssl. To start, I created client and server programs that successfully exchange http requests using DefaultHttpRequest. The code that sends the request looks something like this:
HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "https://localhost:8443");
ChannelBuffer buf = ChannelBuffers.copiedBuffer(line, "UTF-8");
request.setContent(buf);
request.setHeader(HttpHeaders.Names.HOST, host);
request.setHeader(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE);
request.setHeader(HttpHeaders.Names.CONTENT_TYPE, "text/xml");
request.setHeader(HttpHeaders.Names.CONTENT_LENGTH, Integer.toString(buf.capacity()));
ChannelFuture writeFuture = channel.write(request);
The client pipeline factory contains this:
pipeline.addLast("decoder", new HttpResponseDecoder());
pipeline.addLast("encoder", new HttpRequestEncoder());
// and then business logic.
...
The server pipeline factory contains this:
pipeline.addLast("decoder", new HttpRequestDecoder());
pipeline.addLast("encoder", new HttpResponseEncoder());
// and then business logic.
....
So far so good. Client sends, server receives and decodes the request. The messageReceived method on my handler is called with the correct data.
In order to enable the SSL, I've taken some code from the SecureChat example and added to both client and server pipeline factories:
For the server:
SSLEngine engine = SecureChatSslContextFactory.getServerContext().createSSLEngine();
engine.setUseClientMode(false);
pipeline.addLast("ssl", new SslHandler(engine));
// On top of the SSL handler, add the text line codec.
pipeline.addLast("framer", new DelimiterBasedFrameDecoder(
8192, Delimiters.lineDelimiter()));
For the client:
SSLEngine engine = SecureChatSslContextFactory.getClientContext().createSSLEngine();
engine.setUseClientMode(true);
pipeline.addLast("ssl", new SslHandler(engine));
// On top of the SSL handler, add the text line codec.
pipeline.addLast("framer", new DelimiterBasedFrameDecoder(
8192, Delimiters.lineDelimiter()));
Now when I send the request from the client, nothing seems to happen on the server. When I start up the applications, the server seems to connect (channelConnected is called), but when I send the message none of the data gets to the server (messageReceived is never called).
Is there something obviously wrong with what I am doing? Is this the way that https should work? Or is there a different method for sending http requests over ssl?
Thanks,
Weezn
You need to call SslHandler.handshake() on the client side. Check the example again its in there.
Oops, it seems like I copied and pasted too much from the SecureChat example.
Removing the DelimiterBasedFrameDecoder seems to fix the issue.

Check if a file exists on a remote server using Delphi

I need to check if a file exists on a server using delphi..
The idea is to send a request to the server (ex : http://www.example.com/file.txt) and check the status code of the response..
how is it done in delphi?
You can use the TIdHTTP class (included in Delphi). Simply create an instance at run time and use its Head method to retrieve information about the server resource.
MyIdHTTP.Head(TheURL);
ResponseCode := MyIdHTTP.Response.ResponseCode; // 200 = OK etc
ContentLength := MyIdHTTP.Response.ContentLength;
Note that it will not download the whole resource, and the value in ContentLength is not guaranteed ok (for example for dynamically created resources)
hyper(abstract) text transfer protocol.
you can use ftp protocol for this purpose

iis7 website accessed externally downloads files to server instead of local machine

I've a site set up in IIS. It's allows users to download files from a remote cloud to their own local desktop. HOWEVER, the context seems to be mixed up, because when I access the website externally via the IP, and execute the download, it saves the file to the server hosting the site, and not locally. What's going on??
My relevant lines code:
using (var sw2 = new FileStream(filePath,FileMode.Create))
{
try
{
var request = new RestRequest("drives/{chunk}");
RestResponse resp2 = client.Execute(request);
sw2.Write(resp2.RawBytes, 0, resp2.RawBytes.Length);
}
}
Your code is writing a file to the local filesystem of the server. If you want to send the file to the client, you need to do something like
Response.BinaryWrite(resp2.RawBytes);
The Response object is what you use to send data back to the client who made the request to your page.
I imagine that code snippet you posted is running in some sort of code-behind somewhere. That is running on the server - it's not going to be running on the client. You will need to write those bytes in the Response object and specify what content-type, etc. and allow the user to Save the file himself.

Flex RTMP client

I'm trying to write an rtmp client with flex. The problem is that I have no idea where to start. Could someone please answer how I would go about doing this, or point me to a site that does? Thanks. I don't even know what classes to use and such.
See Wiki Real Time Messaging Protocol as a starting point
and there are few sample clients
JUV RTMP Client
php-rtmp-client
hopes that works
You don't have to write your own RTMP client because Flash already implements a RTMP client called NetConnection.
To create a basic connection you could do the following:
var nc:NetConnection = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
nc.connect('rtmp://127.0.0.1/application');
function onNetStatus(e:NetStatusEvent):void
{
switch (e.info.code)
{
case 'NetConnection.Connect.Success':
// Connection with the RTMP server has been established
break;
case '...':
...
}
}
The code 'NetConnection.Connect.Success' you see is one of the codes the server returns, have a look over here for an overview of all the codes.
You should probably read up on the documentation first and then come back with a more precise question.

Resources