diff --git a/libctru/include/3ds/services/httpc.h b/libctru/include/3ds/services/httpc.h index 6e1c0ed..4a16702 100644 --- a/libctru/include/3ds/services/httpc.h +++ b/libctru/include/3ds/services/httpc.h @@ -23,7 +23,7 @@ Result httpcReceiveData(httpcContext *context, u8* buffer, u32 size); Result httpcGetRequestState(httpcContext *context, httpcReqStatus* out); Result httpcGetDownloadSizeState(httpcContext *context, u32* downloadedsize, u32* contentsize); Result httpcGetResponseStatusCode(httpcContext *context, u32* out, u64 delay);//delay isn't used yet. This writes the HTTP status code from the server to out. - +Result httpcGetResponseHeader(httpcContext *context, char* name, char* value, u32 valuebuf_maxsize); Result httpcDownloadData(httpcContext *context, u8* buffer, u32 size, u32 *downloadedsize);//The *entire* content must be downloaded before using httpcCloseContext(), otherwise httpcCloseContext() will hang. //Using the below functions directly is not recommended, use the above functions. See also the http example. @@ -38,5 +38,6 @@ Result HTTPC_BeginRequest(Handle handle, Handle contextHandle); Result HTTPC_ReceiveData(Handle handle, Handle contextHandle, u8* buffer, u32 size); Result HTTPC_GetRequestState(Handle handle, Handle contextHandle, httpcReqStatus* out); Result HTTPC_GetDownloadSizeState(Handle handle, Handle contextHandle, u32* downloadedsize, u32* contentsize); +Result HTTPC_GetResponseHeader(Handle handle, Handle contextHandle, char* name, char* value, u32 valuebuf_maxsize); Result HTTPC_GetResponseStatusCode(Handle handle, Handle contextHandle, u32* out); diff --git a/libctru/source/services/httpc.c b/libctru/source/services/httpc.c index 8b839e8..c8863e8 100644 --- a/libctru/source/services/httpc.c +++ b/libctru/source/services/httpc.c @@ -95,6 +95,11 @@ Result httpcGetDownloadSizeState(httpcContext *context, u32* downloadedsize, u32 return HTTPC_GetDownloadSizeState(context->servhandle, context->httphandle, downloadedsize, contentsize); } +Result httpcGetResponseHeader(httpcContext *context, char* name, char* value, u32 valuebuf_maxsize) +{ + return HTTPC_GetResponseHeader(context->servhandle, context->httphandle, name, value, valuebuf_maxsize); +} + Result httpcGetResponseStatusCode(httpcContext *context, u32* out, u64 delay) { return HTTPC_GetResponseStatusCode(context->servhandle, context->httphandle, out); @@ -294,6 +299,27 @@ Result HTTPC_GetDownloadSizeState(Handle handle, Handle contextHandle, u32* down return cmdbuf[1]; } +Result HTTPC_GetResponseHeader(Handle handle, Handle contextHandle, char* name, char* value, u32 valuebuf_maxsize) +{ + u32* cmdbuf=getThreadCommandBuffer(); + + int name_len=strlen(name)+1; + + cmdbuf[0]=0x001e00c4; //request header code + cmdbuf[1]=contextHandle; + cmdbuf[2]=name_len; + cmdbuf[3]=valuebuf_maxsize; + cmdbuf[4]=(name_len<<14)|0xC02; + cmdbuf[5]=(u32)name; + cmdbuf[6]=(valuebuf_maxsize<<4)|0xC; + cmdbuf[7]=(u32)value; + + Result ret=0; + if((ret=svcSendSyncRequest(handle)))return ret; + + return cmdbuf[1]; +} + Result HTTPC_GetResponseStatusCode(Handle handle, Handle contextHandle, u32* out) { u32* cmdbuf=getThreadCommandBuffer();