Style fixes to HttpRequest

This commit is contained in:
John Scipione 2013-11-04 20:16:26 -05:00
parent f1e63b05cb
commit c2c1ce1dc5
2 changed files with 38 additions and 40 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2010 Haiku Inc. All rights reserved. * Copyright 2010-2013 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _B_URL_PROTOCOL_HTTP_H_ #ifndef _B_URL_PROTOCOL_HTTP_H_
@ -8,7 +8,6 @@
#include <deque> #include <deque>
#include <HttpForm.h> #include <HttpForm.h>
#include <HttpHeaders.h> #include <HttpHeaders.h>
#include <HttpResult.h> #include <HttpResult.h>
@ -29,22 +28,22 @@ public:
BUrlContext* context = NULL); BUrlContext* context = NULL);
virtual ~BHttpRequest(); virtual ~BHttpRequest();
void SetMethod(const char* const method); void SetMethod(const char* const method);
void SetFollowLocation(bool follow); void SetFollowLocation(bool follow);
void SetMaxRedirections(int8 maxRedirections); void SetMaxRedirections(int8 maxRedirections);
void SetReferrer(const BString& referrer); void SetReferrer(const BString& referrer);
void SetUserAgent(const BString& agent); void SetUserAgent(const BString& agent);
void SetDiscardData(bool discard); void SetDiscardData(bool discard);
void SetDisableListener(bool disable); void SetDisableListener(bool disable);
void SetAutoReferrer(bool enable); void SetAutoReferrer(bool enable);
void SetUserName(const BString& name); void SetUserName(const BString& name);
void SetPassword(const BString& password); void SetPassword(const BString& password);
void SetPostFields(const BHttpForm& fields); void SetPostFields(const BHttpForm& fields);
void SetHeaders(const BHttpHeaders& headers); void SetHeaders(const BHttpHeaders& headers);
void AdoptPostFields(BHttpForm* const fields); void AdoptPostFields(BHttpForm* const fields);
void AdoptInputData(BDataIO* const data, void AdoptInputData(BDataIO* const data,
const ssize_t size = -1); const ssize_t size = -1);
void AdoptHeaders(BHttpHeaders* const headers); void AdoptHeaders(BHttpHeaders* const headers);

View File

@ -1,23 +1,26 @@
/* /*
* Copyright 2010-2011 Haiku Inc. All rights reserved. * Copyright 2010-2013 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Christophe Huriaux, c.huriaux@gmail.com * Christophe Huriaux, c.huriaux@gmail.com
* Niels Sascha Reedijk, niels.reedijk@gmail.com * Niels Sascha Reedijk, niels.reedijk@gmail.com
*/ */
#include <HttpRequest.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <cstdlib> #include <cstdlib>
#include <deque> #include <deque>
#include <new> #include <new>
#include <arpa/inet.h>
#include <Debug.h> #include <Debug.h>
#include <File.h> #include <File.h>
#include <Socket.h> #include <Socket.h>
#include <SecureSocket.h> #include <SecureSocket.h>
#include <HttpRequest.h>
static const int32 kHttpBufferSize = 4096; static const int32 kHttpBufferSize = 4096;
@ -260,13 +263,13 @@ BHttpRequest::_ResetOptions()
fOptFollowLocation = true; fOptFollowLocation = true;
fOptMaxRedirs = 8; fOptMaxRedirs = 8;
fOptReferer = ""; fOptReferer = "";
fOptUserAgent = "Services Kit (Haiku)"; fOptUserAgent = "Services Kit (Haiku)";
fOptUsername = ""; fOptUsername = "";
fOptPassword = ""; fOptPassword = "";
fOptAuthMethods = B_HTTP_AUTHENTICATION_BASIC | B_HTTP_AUTHENTICATION_DIGEST fOptAuthMethods = B_HTTP_AUTHENTICATION_BASIC | B_HTTP_AUTHENTICATION_DIGEST
| B_HTTP_AUTHENTICATION_IE_DIGEST; | B_HTTP_AUTHENTICATION_IE_DIGEST;
fOptHeaders = NULL; fOptHeaders = NULL;
fOptPostFields = NULL; fOptPostFields = NULL;
fOptSetCookies = true; fOptSetCookies = true;
fOptDiscardData = false; fOptDiscardData = false;
@ -274,7 +277,7 @@ BHttpRequest::_ResetOptions()
fOptAutoReferer = true; fOptAutoReferer = true;
} }
#include <stdio.h>
status_t status_t
BHttpRequest::_ProtocolLoop() BHttpRequest::_ProtocolLoop()
{ {
@ -344,13 +347,12 @@ BHttpRequest::_ProtocolLoop()
break; break;
case B_HTTP_STATUS_CLASS_CLIENT_ERROR: case B_HTTP_STATUS_CLASS_CLIENT_ERROR:
if(fResult.StatusCode() == B_HTTP_STATUS_UNAUTHORIZED) { if (fResult.StatusCode() == B_HTTP_STATUS_UNAUTHORIZED) {
BHttpAuthentication* authentication BHttpAuthentication* authentication
= &fContext->GetAuthentication(fUrl); = &fContext->GetAuthentication(fUrl);
status_t status = B_OK; status_t status = B_OK;
if (authentication->Method() == B_HTTP_AUTHENTICATION_NONE) if (authentication->Method() == B_HTTP_AUTHENTICATION_NONE) {
{
// There is no authentication context for this // There is no authentication context for this
// url yet, so let's create one. // url yet, so let's create one.
authentication = new BHttpAuthentication(); authentication = new BHttpAuthentication();
@ -506,15 +508,15 @@ BHttpRequest::_MakeRequest()
} else if ((fRequestMethod == B_HTTP_POST || fRequestMethod == B_HTTP_PUT) } else if ((fRequestMethod == B_HTTP_POST || fRequestMethod == B_HTTP_PUT)
&& fOptInputData != NULL) { && fOptInputData != NULL) {
for(;;) { for (;;) {
char outputTempBuffer[kHttpBufferSize]; char outputTempBuffer[kHttpBufferSize];
ssize_t read = fOptInputData->Read(outputTempBuffer, ssize_t read = fOptInputData->Read(outputTempBuffer,
sizeof(outputTempBuffer)); sizeof(outputTempBuffer));
if(read <= 0) break; if (read <= 0)
break;
if (fOptInputDataSize < 0) if (fOptInputDataSize < 0) {
{
// Chunked transfer // Chunked transfer
char hexSize[16]; char hexSize[16];
size_t hexLength = sprintf(hexSize, "%ld", read); size_t hexLength = sprintf(hexSize, "%ld", read);
@ -564,8 +566,7 @@ BHttpRequest::_MakeRequest()
receiveEnd = true; receiveEnd = true;
fInputBuffer.AppendData(chunk.Data(), bytesRead); fInputBuffer.AppendData(chunk.Data(), bytesRead);
} } else
else
bytesRead = 0; bytesRead = 0;
if (fRequestStatus < kRequestStatusReceived) { if (fRequestStatus < kRequestStatusReceived) {
@ -651,9 +652,8 @@ BHttpRequest::_MakeRequest()
// A chunk of 0 bytes indicates the end of the chunked // A chunk of 0 bytes indicates the end of the chunked
// transfer // transfer
if (bytesRead == 0) { if (bytesRead == 0)
receiveEnd = true; receiveEnd = true;
}
} else { } else {
bytesRead = fInputBuffer.Size(); bytesRead = fInputBuffer.Size();
@ -855,13 +855,11 @@ BHttpRequest::_AddHeaders()
fOutputHeaders.AddHeader("Content-Length", fOutputHeaders.AddHeader("Content-Length",
fOptPostFields->ContentLength()); fOptPostFields->ContentLength());
} else if (fOptInputData != NULL } else if (fOptInputData != NULL
&& (fRequestMethod == B_HTTP_POST || fRequestMethod == B_HTTP_PUT)) && (fRequestMethod == B_HTTP_POST || fRequestMethod == B_HTTP_PUT)) {
{ if (fOptInputDataSize >= 0)
if(fOptInputDataSize >= 0) {
fOutputHeaders.AddHeader("Content-Length", fOptInputDataSize); fOutputHeaders.AddHeader("Content-Length", fOptInputDataSize);
} else { else
fOutputHeaders.AddHeader("Transfer-Encoding", "chunked"); fOutputHeaders.AddHeader("Transfer-Encoding", "chunked");
}
} }
// Optional headers specified by the user // Optional headers specified by the user
@ -901,8 +899,9 @@ BHttpRequest::_AddHeaders()
// Write output headers to output stream // Write output headers to output stream
for (int32 headerIndex = 0; headerIndex < fOutputHeaders.CountHeaders(); for (int32 headerIndex = 0; headerIndex < fOutputHeaders.CountHeaders();
headerIndex++) headerIndex++) {
_AddOutputBufferLine(fOutputHeaders.HeaderAt(headerIndex).Header()); _AddOutputBufferLine(fOutputHeaders.HeaderAt(headerIndex).Header());
}
} }